title: Pass arg through new shell within script
body: <p>I'm trying to call a new shell due to a memory leak from a library. When I call the shell, I need to pass an arg (the real code will pass 2 args). After the block of code has executed in the new shell, it needs to return a value. I wrote some test code to reproduce the error:</p>
  
  <pre><code>Function GetLastName
  {
      Param ($firstName)
  
      $lastName = Powershell -firstName $firstName {
          Param ([string]$firstName)
          $lastName = ''
          if ($firstName = 'John')
          {
              $lastName = 'Doe'
              Write-Host "Hello $firstName, your last name is registered as $lastName"
          }
          Write-Host "Last name not found"
          Write-Output $lastName
      }
      Write-Output $lastName
  }
  
  Function Main
  {
      $firstName = 'John'
  
      $lastName = GetLastName $firstName
  
      Write-Host "Your name is $firstName $lastName"
  }
  
  Main
  </code></pre>
  
  <p>The error I get...</p>
  
  <pre>Powershell : -firstName : The term '-firstName' is not recognized as the name of
  a cmdlet, function, script file, or operable
  At C:\Scripts\Tests\test1.ps1:5 char:15
  +         $lastName = Powershell -firstName $firstName {
  +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (-firstName : Th...e, or operable :String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
  
  program. Check the spelling of the name, or if a path was included, verify that
  the path is correct and try again.
  At line:1 char:1
  + -firstName John -encodedCommand DQAKAAkACQAJAFAAYQByAGEAbQAgACgAWwBzAHQAcgBpAG4A ...
  + ~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (-firstName:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException</pre>
  
  <p>Can anyone help me how to do this?</p>