Tagged: powershell parameters strings
- February 4, 2016 at 8:39 am #34855
I'm passing in several file paths as positional parameters to a script like this:
powershell -nologo -file .\Create-AnalysisProps.ps1 "14" "2010=10;2012=11;2013=12;2015=14" "d:\Program Files (x86)\Microsoft Visual Studio ##.0\Team Tools\Static Analysis Tools\FXCop\FXCopCmd.exe" "d:\Program Files (x86)\Microsoft Visual Studio ##.0\Team Tools\Static Analysis Tools\Rule Sets\" "d:\Program Files (x86)\Microsoft Visual Studio ##.0\Team Tools\Static Analysis Tools\FxCop\Metrics.exe" "d:\Program Files (x86)\Microsoft Visual Studio ##.0\Common7\IDE\mstest.exe"
I'm getting the following error:
D:\a6\RWS_Test_Batch_App\Microsoft_Build_Console_App\trunk\Create-AnalysisProps .ps1 : A positional parameter cannot be found that accepts argument 'Studio'.
Here's the Param section of my script:
Param ( # VS Version [Parameter(Position=0)] [string]$VSVersion="2013", # Version Table [Parameter(Position=1)] [string]$VersionTableString="2010=10;2012=11;2013=12;2015=14", # FXCopCmdTemplate [Parameter(Position=2)] [String]$FXCopCmdTemplate="C:\VS ##\Test Tools\FXcopcmd.exe", # FXCopRulesTemplate [Parameter(Position=3)] [String]$FXCopRulesTemplate="C:\VS ##\Rule Sets\", # MSMetricsTemplate [Parameter(Position=4)] [String]$MSMetricsTemplate="C:\VS ##\Test Tools\Metrics.exe", # VSTest Template [Parameter(Position=5)] [String]$VSTestTemplate="C:\VS ##\Test Tools\MSTest.exe", # Output XML File Location [Parameter(Position=6)] [String]$outFilePath )
All my strings are wrapped in quotes. Any idea why this would behave this way? I have other scripts that accept file paths as strings with no problems...February 4, 2016 at 8:48 am #34856
I'm not sure what's doing this, but that trailing backslash before the closing quotation mark in "d:\Program Files (x86)\Microsoft Visual Studio ##.0\Team Tools\Static Analysis Tools\Rule Sets\" is somehow escaping the closing quote and screwing up all the rest of the input. The PowerShell engine doesn't do this; it must be something going on with the console subsystem, or maybe it's something powershell.exe does when you're passing in arguments (so quotes can be escaped from cmd.exe / etc.)
If you're doing this from inside a powershell session already, there's no reason to make another call to powershell.exe. Just do this instead, and the problem goes away:
.\Create-AnalysisProps.ps1 "14" # The rest of your really long command line
If you do need to be calling powershell.exe, then doubling up that trailing backslash works:
"d:\Program Files (x86)\Microsoft Visual Studio ##.0\Team Tools\Static Analysis Tools\Rule Sets\\"February 4, 2016 at 9:10 am #34857
I do need to call PowerShell from Cmd.exe, it's part of a bigger .cmd file where those values actually come from previous steps as %var1% cmd variables. The pre-substitution command looks like:
powershell -file .\Create-AnalysisProps.ps1 "%ver%" "%vertable%" "%fxpath%" etc
Changing the one parameter with the trailing backslash to a double-backslash did the trick. At least the parameters are getting into the script now. Of course I have issues within the script but (theoretically) I can solve those.
You must be logged in to reply to this topic.