title: PowerShell Error - Missing expression after unary operator '-'
body: <p>I have two PowerShell scripts. One is for uninstalling and installing a SharePoint 2010 solution on the SharePoint server. The other calls this script with two commands, one for the uninstall and one for the install. These are not scripts I wrote, but I have inherited them.</p>
  <p>Here is the script that calls the install / uninstall script (I've removed some parameters to simplify for troubleshooting):</p>
  <pre><code>&amp; 'C:\Users\username\Documents\setup.ps1' -InstallOrUninstall '/UNINSTALL'
  &amp; 'C:\Users\username\Documents\setup.ps1' -InstallOrUninstall '/INSTALL'
  </code></pre>
  <p>Stripped down to almost nothing for the purpose of testing, here is the &quot;setup.ps1&quot; script:</p>
  <pre><code>param ($InstallOrUninstall, 
  $SiteURL, 
  $WebURL, 
  [switch]$ignoreFeatures, 
  [switch]$thisAppDomain )
  
  if (-not $thisAppDomain)
  {
       Write-Host &quot;Invoking script in a new app domain&quot;  -foregroundcolor yellow
       Write-Host $MyInvocation.Line
       powershell.exe -Version 2 -Command $MyInvocation.Line -thisAppDomain
       return;
  }
  
  Write-Host &quot;In Body&quot;
  Write-Host $MyInvocation.Line
  </code></pre>
  <p>Running the first script returns an error from the first command, but not from the second. The error is:</p>
  <pre><code>powershell.exe : - : Missing expression after unary operator '-'.
  At C:\Users\username\Documents\setup.ps1:11 char:6
  +      powershell.exe -Version 2 -Command $MyInvocation.Line -thisAppDo ...
  +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (- : Missing exp...y operator '-'.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
   
      + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : MissingExpressionAfterOperator
  </code></pre>
  <p>I believe the reason the install / uninstall script is resending the command for &quot;Version 2&quot; is because of an issue with using PowerShell past Version 2 with SharePoint 2010 (as outlined <a href="https://sharepoint.stackexchange.com/questions/154789/microsoft-sharepoint-is-not-supported-with-version">here</a>). However, I don't understand why only the first line fails. The second command also enters the if statement, but does not error.</p>
  <p>If I remove the second line, and only call the setup.ps1 one time, the script that calls the install / uninstall script succeeds.</p>