我正在尝试使用以下命令从远程计算机到另一台远程计算机使用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并运行此脚本...我完全被困在这里,不确定如何解决它。
发布于 2013-02-02 04:26:04
这似乎和在PowerShell v3上一样有效。我没有v2可以用来测试,但我知道有两个选项,它们应该可以工作。首先,您可以映射PSDrives:
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\"发布于 2016-11-04 04:11:05
这对我来说是一天的工作:
$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将最后一项定义为对象。要复制文件夹的内容,您需要\*
如果要将文件夹本身复制到新位置,则不需要声明内容。
发布于 2021-10-16 03:38:51
我每天都会用到这个:
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#####https://stackoverflow.com/questions/14653851
复制相似问题