2017-12-14 9 views
1

私は、次のPowerShellのコードを持っている:私は、私はそれを保存し、PS1ファイルとしてそれを実行すると、それは動作しますが、それ自身の上でそれぞれの行を実行するとコピー項目

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 

をそれ何もしない。 (私はPowerShellの--version 5.1を使用しています)なぜ

は、誰もがtheincorrigible1 @

+0

なぜセッションでスクリプトを入力していますか? 'Invoke-Command'を利用します。私はあなたが第3ホップの問題にぶつかっていると思いますが – TheIncorrigible1

答えて

1

おかげについて説明することができます - 私は以下にそれを変更したし、それが今取り組んでいます。

$s = New-PSSession -ComputerName test01 
Invoke-Command -Session $s -ScriptBlock { 
New-PSDrive -Name Source -PSProvider FileSystem -Root \\test02\SMBTest - 
Credential test\Administrator 
Copy-Item Source:\Test.txt -Destination C:\Temp 
Remove-PSDrive Source 
}