So I have a pretty simple PowerShell script used to update a version number during a build.
$InputFile = 'D:\BuildAgent\work\c9716e2651305a2e\web\WEB-INF\classes\version.properties'
$OutputFile = $InputFile
Write-Host $('Updating "' + $OutputFile + '" to reflect version "2.10.0.51"')
(Get-Content $InputFile) |
Foreach-Object {
$_ -replace 'version.release\s*:.*','version.release: 2.10.0.51'
} |
Out-File $OutputFile
It works completely fine from within ISE, but when I run it from the command line with
powershell.exe -Command - < powershell2447437064467034590.ps1
or
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy ByPass -Command - < powershell2447437064467034590.ps1
All this does though is blank out the file. How can this work fine from ISE but not from the command line?
-Command - < powershell2447437064467034590.ps1
when you could do it with-File powershell2447437064467034590.ps1
? It could be (but I don't think it is) a threading issue since the ISE is MTA (Multi-Threaded Apartment) and the console is STA (Single-Threaded Apartment) by default. you could try adding the-MTA
switch. – TheMadTechnician-Command - < powershell2447437064467034590.ps1
is how the TeamCity build agent initiates the script. Don't have a whole lot of choice in that matter. – Ultratrunks