title: Is there a way to pass serializable objects to a PowerShell script with start-process?
body: <p>I know about PowerShell jobs, but I want to use start-process and pass a serializable object to the new powershell process.  Is there any way to do this?</p>
  
  <p>It seems that using start-process you have to provide a string argument list which won't cut it for me.  I'm trying to get a PSCredential from one process to another (or a SecureString, I'll take either one).  Maybe this circumvents security.</p>
  
  <hr>
  
  <p>UPDATE - adding the solution I used after seeing help from others (using solution from @PetSerAl)</p>
  
  <p>I wrote two test scripts: a parent script and a child script.  The parent script calls the child script.</p>
  
  <p>Parent Script:</p>
  
  <pre><code>$securePassword = ConvertTo-SecureString "testpassword" -AsPlainText -Force
  $cred = New-Object PSCredential("testuser", $securePassword)
  $credSerial = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes([Management.Automation.PSSerializer]::Serialize($cred)))
  
  $psFile = "C:\repos\Test\PowerShell Scripts\KirkTestChild.ps1"
  $p1 = "-someparam ""this is a test!!!"""
  $p2 = "-cred ""$credSerial"""
  
  $proc = Start-Process PowerShell.exe -PassThru:$true -Argument "-File ""$($psFile)""", $p1, $p2
  Write-Host "ID" $proc.Id
  Write-Host "Has Exited" $proc.HasExited
  
  Start-Sleep -Seconds 15
  Write-Host "Has Exited" $proc.HasExited
  </code></pre>
  
  <p>Child Script:</p>
  
  <pre><code>Param(
      $someParam,
      $cred
  )
  
  Write-Host "someParam: $($someParam)"
  Write-Host "cred (raw): $($cred)"
  $realCred=[Management.Automation.PSSerializer]::Deserialize([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($cred)))
  Write-Host "cred user: $($realCred.UserName)"
  Write-Host "start"
  Start-Sleep 5
  Write-Host "ending"
  Start-Sleep 5
  </code></pre>