Enter-PSSession is not working in my Powershell script Enter-PSSession is not working in my Powershell script powershell powershell

Enter-PSSession is not working in my Powershell script


Not sure if it is a timing issue. I suspect it's more like Enter-PSSession is invoking something like a nested prompt and your subsequent commands are not executing within it. Anyway, I believe Enter/Exit-PSSession is meant for interactive use - not scripting use. For scripts use New-PSSession and pass that session instance into Invoke-Command e.g.:

$cred = Get-Credential domain\DanTest $s = New-PSSession -computerName xsappb01 -credential $credInvoke-Command -Session $s -Scriptblock {New-Item -type file c:\temp\blah.txt}Remove-PSSession $s