我已经成功地让 winrm 工作,我能够Enter-PSSession my-machine
在 shell 中运行并随后输入命令。但是,当我尝试运行启动远程会话的脚本时,所有后续调用都在本地计算机上运行。例如:
PS> test.ps1
test.ps1 的内容
Enter-PSSession remote-pcname
gc env:computername
打印出来local-pcname
而不是remote-pcname
知道为什么脚本文件不尊重远程会话?它肯定是成功连接,因为当脚本完成时,我返回到远程机器的 shell 提示符。