【发布时间】:2017-12-14 17:26:50
【问题描述】:
我有以下 Powershell 代码:
Enter-PSSession -ComputerName test01
New-PSDrive -Name Source -PSProvider FileSystem -Root \\test02\SMBTest -Credential test\Administrator
Copy-Item Source:\Test.txt -Destination C:\Temp
Remove-PSDrive Source
Exit-PSSession
当我自己执行每一行时,它可以工作,但是当我将它保存并作为 ps1 文件运行时,它什么也不做。
谁能帮忙解释一下原因(我使用的是 Powershell --version 5.1)
【问题讨论】:
-
为什么要在脚本中输入会话?使用
Invoke-Command。虽然我认为你遇到了第三跳问题
标签: powershell copy-item