When the TeamCity Powershell runner runs my .ps1 file it doesn't recognize the Write-Zip command, which is part of the Powershell community extensions.
I can run the same command manually on the build server and it works just fine. I've verified that both TeamCity and I are running the x64 version of powershell.exe and both are running as the same user.
[17:21:22][Step 5/5] Packaging WWW.zip
[17:21:45][Step 5/5] Write-Zip : The term 'Write-Zip' is not recognized as the name of a cmdlet,
[17:21:45][Step 5/5] function, script file, or operable program. Check the spelling of the name, or
[17:21:45][Step 5/5] if a path was included, verify that the path is correct and try again.
[17:21:45][Step 5/5] At
[17:21:45][Step 5/5] C:\TeamCity\buildAgent\work\e19b1309c030c7e2\Build\PowerShell\Package.ps1:20
[17:21:45][Step 5/5] char:1
[17:21:45][Step 5/5] + Write-Zip -InputObject $items -OutputPath .\WWW.zip
[17:21:45][Step 5/5] + ~~~~~~~~~
[17:21:45][Step 5/5] + CategoryInfo : ObjectNotFound: (Write-Zip:String) [], CommandNo
[17:21:45][Step 5/5] tFoundException
[17:21:45][Step 5/5] + FullyQualifiedErrorId : CommandNotFoundException
[17:21:45][Step 5/5]
I think it may be related to powershell being run from a different environment but I don't fully understand this yet.
I found in the TeamCity build logs that the script is being run like this:
C:\Windows\sysnative\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -File C:\TeamCity\buildAgent\work\e19b1309c030c7e2\Build\PowerShell\Package.ps1 -WorkingDirectory C:\TeamCity\buildAgent\work\e19b1309c030c7e
Notice that powershell is being run by C:\Windows\sysnative\cmd.exe
However, on the build server, I don't see this directory or version of cmd.exe, and if I try to run the same command from PowerShell or Command Prompt, it says that it can't find C:\Windows\sysnative\cmd.exe
Does anyone know how TeamCity actually runs Powershell?
Update
I tried running my powershell script using the Command Line Runner and then calling powershell.exe with the -File command just like TeamCity would do.
I had TaskManager running and saw the cmd.exe process it ran was C:\Windows\SysWOW64\cmd.exe
I got the exact same error as printed above, Write-Zip is not recognized. However, if I run the same command in ...\SysWOW64\cmd.exe manually, it works.
Once again, both running as the same user on the same machine, according to TaskManager