20

Copy-Item次のコマンドを使用して、リモートマシンから別のリモートマシンに使用しようとしています。

Copy-Item -Path "\\machine1\abc\123\log 1.zip" -Destination "\\machine2\\c$\Logs\"

常にエラーが発生します" Cannot find Path "\\machine1\abc\123\log 1.zip"

そのパスにアクセスして、そこから手動でコピーできます。

管理者としてPowerCLIを開いて、このスクリプトを実行しています...私はここで完全に立ち往生しており、解決方法がわかりません。

4

3 に答える 3

26

これは PowerShell v3 でそのまま動作するようです。テストするのに便利なv2はありませんが、私が知っている2つのオプションがあり、どちらも機能するはずです。まず、PSDrive をマップできます。

New-PSDrive -Name source -PSProvider FileSystem -Root \\machine1\abc\123 | Out-Null
New-PSDrive -Name target -PSProvider FileSystem -Root \\machine2\c$\Logs | Out-Null
Copy-Item -Path source:\log_1.zip -Destination target:
Remove-PSDrive source
Remove-PSDrive target

これを頻繁に行う場合は、これを関数でラップすることもできます。

Function Copy-ItemUNC($SourcePath, $TargetPath, $FileName)
{
   New-PSDrive -Name source -PSProvider FileSystem -Root $SourcePath | Out-Null
   New-PSDrive -Name target -PSProvider FileSystem -Root $TargetPath | Out-Null
   Copy-Item -Path source:\$FileName -Destination target:
   Remove-PSDrive source
   Remove-PSDrive target
}

または、各パスでプロバイダを明示的に指定できます。

Copy-Item -Path "Microsoft.PowerShell.Core\FileSystem::\\machine1\abc\123\log 1.zip" -Destination "Microsoft.PowerShell.Core\FileSystem::\\machine2\\c$\Logs\"
于 2013-02-01T20:26:04.123 に答える
3

これは私にとって一日中機能します:

$strLFpath = "\\compname\e$\folder"
$strLFpath2 = "\\Remotecomputer\networkshare\remotefolder"  #this is a second option that also will work
$StrRLPath = "E:\localfolder"  
Copy-Item -Path "$StrRLPath\*" -Destination "$strLFpath" -Recurse -force -Verbose

注意事項: Copy-item は、LAST アイテムをオブジェクトとして定義します。\* が必要なフォルダの内容をコピーするには

フォルダー自体を新しい場所にコピーする場合は、コンテンツを宣言する必要はありません。

于 2016-11-03T20:11:05.117 に答える
0

私はこれを毎日使用しています:

Robocopy /E \\\SOURCEIP\C$\123\  \\\DESTIP\C$\Logs\   
                                             

真ん中に空きスペースがあります。ROBCOPY の場合、/E はコピーを行います。移動する必要がある場合は、グーグルで検索できます。

または:

$SourceIP = Read-Host "Enter the Source IP"

$DESTIP = Read-Host "Enter the Destination IP"

Robocopy /E \\\\$SourceIP\C$\123\  \\\\$DESTIP\C$\Logs\ 

####Just adjust the C$ path on both#####
于 2021-10-16T03:38:50.743 に答える