Error running SetTimeZone cmlet in provisioner "powershell"

This section is erroring out in packer build
Error details
Set-TimeZone : The term ‘Set-TimeZone’ is not recognized as the name of a cmdlet, function , script file, or operable program

The build section of my *.pkr.hcl is shown below - does this command need any elevated priveleges that I am supposed to set ?

build {
name = “learn-packer”
sources = [“source.amazon-ebs.firstrun-windows”]

provisioner “powershell” {
environment_vars = [“DEVOPS_LIFE_IMPROVER=PACKER”]
inline = [“Write-Host "HELLO NEW USER; WELCOME TO Env:DEVOPS_LIFE_IMPROVER\"", "Write-Host \"You need to use backtick escapes when using\"", "Write-Host \"characters such as DOLLAR` directly in a command"”, “Write-Host "or in your own scripts."”]
}
provisioner “windows-restart” {
}
provisioner “powershell” {
environment_vars = [“VAR1=A$Dollar”, “VAR2=A`Backtick”, “VAR3=A’SingleQuote”, “VAR4=A"DoubleQuote”]
script = “./sample_script.ps1”
}
provisioner “powershell” {
environment_vars = [“WINRMPASS=${build.Password}”]
inline = [“Write-Host "Automatically generated aws password is: $Env:WINRMPASS"”]
}
// test script to write file on the windows server directory
provisioner “powershell” {
inline = [“Set-TimeZone "Central Standard Time"”]

}
}

This still fails with the same error above even with “Set-TimeZone -Id Central Standard Time” set within a script and pointed to using script = …
Is Set-TimeZone not accepted as powershell command in provisioners ?

Hi ! It should work that weird.
For testing purpose, could you use the windows shell provisioner instead of powershell, just to check if it fails again or not ?

Maybe it’s not comparable but i had the same kind of issue with Ansible, specially on some cmdlets…so i still compare both provisionner if available :slight_smile: