hashicorp / hashicorp/packer

Powershell provisioner doesn't set $ProgressPreference='SilentlyContinue'

Open
#13,490 0 comments 0 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

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

#### Overview of the Issue

Powershell provisioner doesn't set `$ProgressPreference='SilentlyContinue'`

#### Reproduction Steps

1. create a test powershell script (`test.ps1`) that prints out the `$ProgressPreference` variable.
```
Write-Output $ProgressPreference
```
2. call the test powershell script in `build.pkr.hcl`
```
build {
sources = [
"source.vsphere-clone.windows-11-23H2",
]

provisioner "powershell" {
only = ["vsphere-clone.windows-11-23H2"]
scripts = [
"test.ps1",
]
}
}
```
3. Run packer
```
...
==> vsphere-clone.windows-11-23H2: Provisioning with Powershell...
==> vsphere-clone.windows-11-23H2: Provisioning with powershell script: test.ps1
vsphere-clone.windows-11-23H2: Continue
...
```

Expected `SilentlyContinue` to be printed. Looking the documentation, the default powershell provisioner command looks like the following

```
powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};. {{.Vars}}; &'{{.Path}}'; exit $LastExitCode }"
```

which should have set `ProgressPreference` to `SilentlyContinue`. If we just place the logic in a powershell script, I think it reproduces the problem.

```
if (Test-Path variable:global:ProgressPreference) {
set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'
}

Write-Output $ProgressPreference
```

### Packer version

From `packer version`

```
Packer v1.14.2
```

### Operating system and Environment details

- Windows 11 23H2
- vSphere

### Log Fragments and crash.log files

```
==> vsphere-clone.windows-11-23H2: Provisioning with Powershell...
==> vsphere-clone.windows-11-23H2: Provisioning with powershell script: test.ps1
2025/10/06 10:27:21 packer.exe plugin: Opening test.ps1 for reading
2025/10/06 10:27:21 packer.exe plugin: Uploading env vars to c:/Windows/Temp/packer-ps-env-vars-68e3fbf9-d2f4-561c-b68a-eac300383f9d.ps1
2025/10/06 10:27:21 packer.exe plugin: [INFO] 187 bytes written for 'uploadData'
2025/10/06 10:27:21 [INFO] 187 bytes written for 'uploadData'
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Opening new ssh session
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Starting remote scp process: scp -vt c:/Windows/Temp
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Started SCP session, beginning transfers...
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Copying input data into temporary file so we can read the length
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] scp: Uploading packer-ps-env-vars-68e3fbf9-d2f4-561c-b68a-eac300383f9d.ps1: perms=C0644 size=187
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] SCP session complete, closing stdin pipe.
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Waiting for SSH session to complete.
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] scp stderr (length 77): Sink: C0644 187 packer-ps-env-vars-68e3fbf9-d2f4-561c-b68a-eac300383f9d.ps1
2025/10/06 10:27:21 packer.exe plugin: [INFO] 32 bytes written for 'uploadData'
2025/10/06 10:27:21 [INFO] 32 bytes written for 'uploadData'
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Opening new ssh session
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Starting remote scp process: scp -vt c:/Windows/Temp
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] Started SCP session, beginning transfers...
2025/10/06 10:27:21 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:21 [DEBUG] scp: Uploading script-68e3fbf9-b167-3c0f-ec86-b2847612f2a2.ps1: perms=C0666 size=32
2025/10/06 10:27:22 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:22 [DEBUG] SCP session complete, closing stdin pipe.
2025/10/06 10:27:22 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:22 [DEBUG] Waiting for SSH session to complete.
2025/10/06 10:27:22 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:22 [DEBUG] scp stderr (length 64): Sink: C0666 32 script-68e3fbf9-b167-3c0f-ec86-b2847612f2a2.ps1
2025/10/06 10:27:22 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:22 [DEBUG] Opening new ssh session
2025/10/06 10:27:22 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:22 [DEBUG] starting remote command: powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'};. c:/Windows/Temp/packer-ps-env-vars-68e3fbf9-d2f4-561c-b68a-eac300383f9d.ps1; &'c:/Windows/Temp/script-68e3fbf9-b167-3c0f-ec86-b2847612f2a2.ps1'; exit $LastExitCode }"
==> vsphere-clone.windows-11-23H2: Continue
2025/10/06 10:27:24 packer-plugin-vsphere_v2.0.0_x5.0_windows_amd64.exe plugin: 2025/10/06 10:27:24 [INFO] RPC endpoint: Communicator ended with: 0
2025/10/06 10:27:24 [INFO] 10 bytes written for 'stdout'
2025/10/06 10:27:24 [INFO] 0 bytes written for 'stderr'
2025/10/06 10:27:24 [INFO] RPC client: Communicator ended with: 0
2025/10/06 10:27:24 [INFO] RPC endpoint: Communicator ended with: 0
2025/10/06 10:27:24 packer.exe plugin: [INFO] 10 bytes written for 'stdout'
2025/10/06 10:27:24 packer.exe plugin: [INFO] 0 bytes written for 'stderr'
2025/10/06 10:27:24 packer.exe plugin: [INFO] RPC client: Communicator ended with: 0
2025/10/06 10:27:24 packer.exe plugin: c:/Windows/Temp/script-68e3fbf9-b167-3c0f-ec86-b2847612f2a2.ps1 returned with exit code 0
2025/10/06 10:27:24 packer.exe plugin: [INFO] 511 bytes written for 'uploadData'
2025/10/06 10:27:24 [INFO] 511 bytes written for 'uploadData'
```

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.