EC2 Windows User Data: Powershell does not run as expected EC2 Windows User Data: Powershell does not run as expected powershell powershell

EC2 Windows User Data: Powershell does not run as expected


The issue was that when installed as part of the cloud init process, the Powershell profile fails to import Chocolatey. This means that packages will install fine via choco install, but are not made available in the environment, even if you call refreshenv (hence my call to aws failed even though it installed successfully.)

To fix this problem you can manually force Powershell to import the Chocolatey module by editing your Powershell profile.

# Updated profile content to explicitly import Choco$ChocoProfileValue = @'$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"if (Test-Path($ChocolateyProfile)) {  Import-Module "$ChocolateyProfile"}'@# Write it to the $profile locationSet-Content -Path "$profile" -Value $ChocoProfileValue -Force# Source it. $profile

You can read more on this in the chocolatey troubleshooting guide