{"record":{"id":"8e56a1a6436683f2","repo":"hashicorp/packer","slug":"only-a-script-file-or-an-inline-script-can-be-spec","errorCode":null,"errorMessage":"Only a script file or an inline script can be specified, not both.","messagePattern":"Only a script file or an inline script can be specified, not both\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":243,"sourceCode":"\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Only one of script or scripts can be specified.\"))\n\t}\n\n\tif p.config.ElevatedUser == \"\" && p.config.ElevatedPassword != \"\" {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Must supply an 'elevated_user' if 'elevated_password' provided\"))\n\t}\n\n\tif p.config.Script != \"\" {\n\t\tp.config.Scripts = []string{p.config.Script}\n\t}\n\n\tif len(p.config.Scripts) == 0 && p.config.Inline == nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Either a script file or inline script must be specified.\"))\n\t} else if len(p.config.Scripts) > 0 && p.config.Inline != nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Only a script file or an inline script can be specified, not both.\"))\n\t}\n\n\tif p.config.ExecuteCommand == \"\" {\n\t\tif p.config.Inline != nil && len(p.config.Scripts) == 0 {\n\t\t\tp.config.ExecuteCommand = p.defaultExecuteCommand()\n\t\t\tlog.Printf(\"Using inline default execute command %s\", p.config.ExecuteCommand)\n\t\t} else {\n\t\t\tp.config.ExecuteCommand = p.defaultScriptCommand()\n\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 {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L225-L261","documentation":"The PowerShell provisioner can execute a script file list or an inline script array, but not both, since they would use different execute_command strategies. Prepare rejects a block where scripts is non-empty and inline is also provided. The ambiguity is resolved by making the choice explicit in the template.","triggerScenarios":"A powershell provisioner block setting both scripts (or script, which is folded into scripts) and inline, e.g. scripts = [\"./a.ps1\"] plus inline = [\"dir\"].","commonSituations":"Extending an existing file-based provisioner with a quick inline command instead of appending to the script; copy-paste merges of two provisioner blocks; conditional HCL where both branches contribute fields.","solutions":["Remove the inline field and put the commands into the .ps1 file(s) referenced by scripts.","Or remove script(s) and use only inline if no file-based script is needed.","If both payloads are genuinely needed, split into two provisioner blocks — one file-based, one inline."],"exampleFix":"// before\nprovisioner \"powershell\" {\n  scripts = [\"./setup.ps1\"]\n  inline  = [\"Write-Host done\"]\n}\n\n// after\nprovisioner \"powershell\" {\n  scripts = [\"./setup.ps1\"]\n}\nprovisioner \"powershell\" {\n  inline = [\"Write-Host done\"]\n}","handlingStrategy":"validation","validationCode":"// Choose exactly one payload style:\nassert {\n  condition     = !(length(var.ps_scripts) > 0 && length(var.ps_inline) > 0)\n  error_message = \"Use either scripts or inline in a powershell provisioner, not both.\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep file-based and inline payloads in separate provisioner blocks.","When adding quick commands to an existing block, append them to the script file instead of adding inline.","Run packer validate after template merges."],"tags":["packer","provisioner","powershell","config-validation"],"backgroundTag":"mutually-exclusive-fields","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"}