title: Powershell - pass PSCredential object to new command window
body: <p>I have a powershell script which calls Get-Credential. The entered credentials are to be used against multiple servers later on in the script and child scripts.</p>
  
  <p>The code looks something like:</p>
  
  <pre><code>$credentials = get-credential
  CMD /c start powershell.exe -noexit -File subscript.ps1 $credentials
  </code></pre>
  
  <p>The issue is inside subscript.ps1 I have this code just to see whats coming in:</p>
  
  <pre><code>$args.length
  $args[0]
  </code></pre>
  
  <p>which gives me
  1
  System.Management.Automation.PSCredential</p>
  
  <p>As you can see it does not pass the actual object returned by the Get-Credential call.</p>
  
  <p>My guess is this is happening because we are calling the script by a new command window. We need to open a new command window as we need to open 4 different subscript.ps1 (with different parameters for parallel processing).</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks,
  Andrew</p>