title: Launch PowerShell script into new window while passing variables
body: <p>I've been using the site for a while, searching through the questions and answers, trying to map them to my scenario, but I'm either missing something, or what I'm looking to do isn't possible (at least the way I'm trying to do it), hence I'm hoping for a push in the right direction. Thanks in advance for reading.</p>
  
  <p>I've been working on a fairly sizeable automation project. My main script performs a number of tasks, and generally works well, and reliably. At one stage of the script, I execute another PowerShell script, which was written by another team. I call the script as follows:</p>
  
  <pre><code>.\DeployMySQLProvider.ps1 -AzCredential $asdkCreds `
  -VMLocalCredential $vmLocalAdminCreds `
  -CloudAdminCredential $cloudAdminCreds
  -PrivilegedEndpoint $ERCSip `
  -DefaultSSLCertificatePassword $secureVMpwd -AcceptLicense
  </code></pre>
  
  <p>When I call it this way, from my main script, it works fine, however, this script uses and registers a DLL file during it's deployment, and locks it until the PowerShell window and session is closed. At the end of my main script, I have a cleanup phase, which can't complete it's job because of this locked DLL.</p>
  
  <p>My thoughts therefore, were to launch the 2nd script into a new PowerShell window and session, either using Start-Process or Invoke-Expression, but I just can't seem to get either right. Most of the variables I'm passing through to the 2nd script aren't just strings, which is probably where I'm falling over. They are a mix of usernames and passwords (secure strings) along with $ERCSip which is a string.</p>
  
  <p>Should I be looking at Start-Process / Invoke-Expression, or something else entirely? When I was testing with Start-Process, I had the following defined, but couldn't get the ArgumentList side working correcly for me (blank below):</p>
  
  <pre><code>Start-Process "$pshome\powershell.exe" -PassThru -Wait `
  -Verb RunAs -ErrorAction Stop -ArgumentList ""
  </code></pre>
  
  <p>Any pointers in the right direction would be much appreciated.</p>
  
  <p>Thanks!</p>