{"record":{"id":"f9dd363eed8075bd","repo":"hashicorp/packer","slug":"bad-script-s-s","errorCode":null,"errorMessage":"Bad script '%s': %s","messagePattern":"Bad script '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":270,"sourceCode":"\t\t\tlog.Printf(\"Using script default execute command %s\", p.config.ExecuteCommand)\n\t\t}\n\n\t}\n\n\tif p.config.ElevatedExecuteCommand == \"\" {\n\t\tif p.config.Inline != nil && len(p.config.Scripts) == 0 {\n\t\t\tp.config.ElevatedExecuteCommand = p.defaultExecuteCommand()\n\t\t\tlog.Printf(\"Using inline default elevated execute command %s\", p.config.ElevatedExecuteCommand)\n\t\t} else {\n\t\t\tp.config.ElevatedExecuteCommand = p.defaultScriptCommand()\n\t\t\tlog.Printf(\"Using script default elevated execute command %s\", p.config.ElevatedExecuteCommand)\n\t\t}\n\t}\n\n\tfor _, path := range p.config.Scripts {\n\t\tif _, err := os.Stat(path); err != nil {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Bad script '%s': %s\", path, err))\n\t\t}\n\t}\n\n\t// Do a check for bad environment variables, such as '=foo', 'foobar'\n\tfor _, kv := range p.config.Vars {\n\t\tvs := strings.SplitN(kv, \"=\", 2)\n\t\tif len(vs) != 2 || vs[0] == \"\" {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Environment variable not in format 'key=value': %s\", kv))\n\t\t}\n\t}\n\n\tif p.config.ExecutionPolicy > 7 {\n\t\terrs = packersdk.MultiErrorAppend(errs, fmt.Errorf(`Invalid execution `+\n\t\t\t`policy provided. Please supply one of: \"bypass\", \"allsigned\",`+\n\t\t\t` \"default\", \"remotesigned\", \"restricted\", \"undefined\", `+\n\t\t\t`\"unrestricted\", \"none\".`))\n\t}","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L252-L288","documentation":"During PowerShell provisioner Prepare, each configured script path is checked with os.Stat. If a path cannot be stat-ed (missing file, bad permissions, or invalid path), the provisioner reports \"Bad script '%s': %s\" embedding the underlying OS error. Prepare returns accumulated errors so template validation fails before any build runs.","triggerScenarios":"Calling Provisioner.Prepare with config.Scripts containing a path that does not exist, points to a directory, or is otherwise unstatable (os.Stat returns non-nil err).","commonSituations":"Typo in the script path; relative path resolved against a different working directory (packer run from another cwd); script deleted or moved after writing the template; Windows path separators mixed up; path points to a directory instead of a .ps1 file.","solutions":["Correct the `scripts` entry in the template so each path exists; test with `ls <path>`/`Test-Path <path>` in the same directory packer runs from.","Use absolute paths or template variables ({{path_root}}/packer start-dir) so relative resolution is not cwd-dependent.","Verify file permissions allow reading by the user running packer.","If generating scripts dynamically, use `inline` instead of `scripts` so the provisioner creates the file itself."],"exampleFix":"// before\n\"scripts\": [\"./scrpts/bootstrap.ps1\"]\n// after\n\"scripts\": [\"./scripts/bootstrap.ps1\"]","handlingStrategy":"validation","validationCode":"// Go, before calling Prepare\nfor _, p := range cfg.Scripts {\n    if fi, err := os.Stat(p); err != nil {\n        return fmt.Errorf(\"script %q unavailable: %w\", p, err)\n    } else if fi.IsDir() {\n        return fmt.Errorf(\"script %q is a directory\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go\nif err := prov.Prepare(cfg); err != nil {\n    var pathErr *os.PathError\n    if errors.As(err, &pathErr) {\n        // fix or remove the offending script path in cfg.Scripts\n    }\n    return err\n}","preventionTips":["Keep script paths absolute or anchored to a known packer start directory.","Run `packer validate` before every build; it exercises Prepare.","Keep scripts inside the project tree so they aren't lost with temp cleanup.","Lint templates in CI to catch typos in script paths."],"tags":["powershell","provisioner","file-not-found","configuration"],"backgroundTag":"script-file-not-found","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}