hashicorp / hashicorp/packer

PowerShell Scripts are randomly not recognized

Open
#13,360 15 comments 5 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
15.8k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

#### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment

#### Overview of the Issue

The renamed PowerShell script will randomly not be recognized. Rerunning usually fixes it, but it inconsistent how often it happens. The script technically still runs, but Packer will move on from it and run the next script async. If the next one depends on the previous one, the whole build will error out. This was reported [here](https://github.com/hashicorp/packer/issues/9400) but for some reason, it was closed because someone explained a workaround. A workaround is not a fix, and even the workaround still fails in certain cases (that issue should never have been closed).

The workaround explained in the closed issue is to install PowerShell 7+ first and the making the rest of the scripts run using pwsh. The problem is that sometimes, the script that is responsible for installing PowerShell 7 will result in the same missing script, so Packer will move on before PowerShell 7 finishes installing and then the following script fails because pwsh is not a valid command.

#### Reproduction Steps

I don't have any steps, it randomly happens, and based on the closed issue I linked earlier, its been happening in multiple versions randomly for years.

### Packer version

`1.12.0`

### Operating system and Environment details

I'm trying to generate a Windows Server 2025 AWS AMI. The ID of the base AMI is ami-02e3d076cbd5c28fa.

### Log Fragments and crash.log files

```
==> amazon-ebs.autogenerated_1: Connected to WinRM!
==> amazon-ebs.autogenerated_1: Provisioning with Powershell...
==> amazon-ebs.autogenerated_1: Provisioning with powershell script: ./install_latest_powershell.ps1

==> amazon-ebs.autogenerated_1: & : The term 'c:/Windows/Temp/script-68027f1b-f980-cad7-1a3a-bdd61649891d.ps1' is not recognized as the name of a
==> amazon-ebs.autogenerated_1: cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
==> amazon-ebs.autogenerated_1: that the path is correct and try again.
==> amazon-ebs.autogenerated_1: At line:1 char:216
==> amazon-ebs.autogenerated_1: + ... 84a8c.ps1; &'c:/Windows/Temp/script-68027f1b-f980-cad7-1a3a-bdd616498 ...
==> amazon-ebs.autogenerated_1: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> amazon-ebs.autogenerated_1: + CategoryInfo : ObjectNotFound: (c:/Windows/Temp...dd61649891d.ps1:String) [], CommandNotFoundException
==> amazon-ebs.autogenerated_1: + FullyQualifiedErrorId : CommandNotFoundException

==> amazon-ebs.autogenerated_1: Uploading windows_update_installer/ => C:/Temp/windows_update_installer
==> amazon-ebs.autogenerated_1: Provisioning with Powershell...
==> amazon-ebs.autogenerated_1: Provisioning with powershell script: C:\Windows\SystemTemp\powershell-provisioner3154523837

amazon-ebs.autogenerated_1: 'pwsh' is not recognized as an internal or external command,
amazon-ebs.autogenerated_1: operable program or batch file.

==> amazon-ebs.autogenerated_1: Provisioning step had errors: Running the cleanup provisioner, if present...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.