Teamcity Seems to Corrupt Powershell Scripts

powershell, teamcity

Solution

The solution was much simpler that it should have been. There is an option in teamcity called "Script execution mode", which I changed from `Put script into PowerShell stdin with "-Command -" arguments` to `Execute .ps1 script with "-File" argument` once that was done the script started running as expected.

Problem

I have a powershell script that I am trying to run via teamcity. The script is stored in the git repo that the code is built from. I have set teamcity to run the script as a script file If I run the script from a powershell commandline on the build sever it runs as expected, if I run the same script from teamcity I get errors like ``` [16:04:25][Step 3/3] Get-Date : Cannot bind parameter 'Date'. Cannot convert value "–f" to type [16:04:25][Step 3/3] "System.DateTime". Error: "The string was not recognized as a valid DateTime. [16:04:25][Step 3/3] There is an unknown word starting at index 0." [16:04:25][Step 3/3] At line:1 char:26 [16:04:25][Step 3/3] + Write-Output "$(Get-Date –f $timeStampFormat) - Upgrading Deployment: In [16:04:25][Step 3/3] progr ... [16:04:25][Step 3/3] + ~~~~ [16:04:25][Step 3/3] + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindin [16:04:25][Step 3/3] gException [16:04:25][Step 3/3] + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh [16:04:25][Step 3/3] ell.Commands.GetDateCommand [16:04:25][Step 3/3] ``` Why might this be happening?

Original source