PowerShell 输入会话查找路径错误 [英] PowerShell Enter Session find path bug
本文介绍了PowerShell 输入会话查找路径错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些自动化脚本,但我不得不将它们拆分,因为这似乎是一个有趣的错误.我已将其剥离为以下最简单的形式:
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?
推荐答案
使用 Invoke-Command 而不是 enter-pssession
.
示例:
$ReturnValue = Invoke-Command -ComputerName $Server -ScriptBlock{
Set-Location D:
# DO STUFF
Return $ReturnValue # Return your stuff
}
这篇关于PowerShell 输入会话查找路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文