# Complex strings as positional parameters

**URL:** <https://forums.powershell.org/t/complex-strings-as-positional-parameters/5695>\
**Category:** PowerShell Help\
**Created:** [February 4, 2016, 3:09am UTC](https://forums.powershell.org/t/complex-strings-as-positional-parameters/5695 "2016-02-04T03:09:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard-schaefer](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@richard-schaefer](https://forums.powershell.org/u/richard-schaefer)\
**Post date:** [February 4, 2016, 3:09am UTC](https://forums.powershell.org/t/complex-strings-as-positional-parameters/5695/1 "2016-02-04T03:09:55Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [February 4, 2016, 3:18am UTC](https://forums.powershell.org/t/complex-strings-as-positional-parameters/5695/2 "2016-02-04T03:18:19Z")

</div>

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\”

---

<div class="post-metadata">

**Author:** ![richard-schaefer](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@richard-schaefer](https://forums.powershell.org/u/richard-schaefer)\
**Post date:** [February 4, 2016, 3:40am UTC](https://forums.powershell.org/t/complex-strings-as-positional-parameters/5695/3 "2016-02-04T03:40:49Z")

</div>

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.

Thanks.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:43pm UTC](https://forums.powershell.org/t/complex-strings-as-positional-parameters/5695/4 "2024-05-16T20:43:00Z")

</div>


