PowerShell Enter Session find path bug

别等时光非礼了梦想. 提交于 2019-12-12 04:57:47

问题


I have some automation scripts, but I had to split them down because of what appears to be an interesting bug. I've stripped it to its simplest form below:

Enter-PSSession [SERVER]
cd D:\

If I run the above in one go, I get the below error

cd : Cannot find drive. A drive with the name 'D' does not exist.

However, if I run the lines individually, they run fine. I have tried putting a sleep in for a second, a pause line, but still no luck. Is anyone else aware of this, and the way around it?


回答1:


Use Invoke-Command instead of enter-pssession.

Example:

$ReturnValue = Invoke-Command -ComputerName $Server -ScriptBlock{
    Set-Location D:
    # DO STUFF
    Return $ReturnValue # Return your stuff
}


来源:https://stackoverflow.com/questions/45957307/powershell-enter-session-find-path-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!