title: Enter-PSSession with -Credential still prompts for credentials when inside a ScriptBlock
body: <p>I have a script that automatically logs a user into a remote PowerShell session using Enter-PSSession. I create the -Credential with New-Object System.Management.Automation.PSCredential. This works great if it is not inside a ScriptBlock. When I put it inside a script block it prompts me for credentials when it tries to connect and I am not sure why.</p>
  
  <p>How would I make it so it works inside the ScriptBlock?</p>
  
  <pre><code>$userADPW = "password"
  
  $userAD = "john"
  
  $servip = "Server2K81.homelab.com"
  
  $PassSec = ConvertTo-SecureString $userADPW -AsPlainText -Force
  
  $credentialPS = New-Object System.Management.Automation.PSCredential ($userAD,$PassSec)
  
  Start-Job -ScriptBlock {param($psip,$CredentialPS2) Start-Process powershell -Argumentlist '-noexit',"Enter-PSSession -ComputerName $psip -Credential $CredentialPS2" -passthru -Wait} -ArgumentList $servip,$credentialPS
  </code></pre>