Make PowerShell ignore semicolon

Just escape the semicolon on the command line:

msbuild /t:Build`;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Debug`;_PackageTempDir=$TargetFolder $WebProject

I do this all the time with the tf.exe utility:

tf.exe status . /r /workspace:WORK`;johndoe

FYI, this issue has been heavily voted up on Connect. PowerShell v3 addresses this issue with the new --% operator:

$env:TargetFolder = $TargetFolder
msbuild $WebProject --% /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Debug;_PackageTempDir=%TargetFolder%

Try using Start-Process to run MSbuild then pass the rest as a value with -Argument.


The easiest way to ignore a semicolon? Simply use a single quote versus double quote!

In PowerShell, the type of quote you use matters. A double quote will let PowerShell do string expansion (so if you have a variable $something = someprogram.exe, and run "$something", PowerShell substitutes in "someprogram.exe").

If you don't need string substitution/variable expansion then just use single-quotes. PowerShell will execute single-quoted strings exactly as listed.

Another option if you want to use string expansion is to use a here-string instead. A here string is just like a regular string, however it begins and ends with an @ sign on its own separate line, like so:

$herestring = @"
Do some stuff here, even use a semicolon ;
"@

This is a best-of-both-worlds scenario, as you can use your fancy characters and have them work, but still get Variable expansion, which you do not get with single-quotes.

Tags:

Powershell