需要有关来自网络驱动器的 Powershell Copy-Item 的帮助 [英] Need help on Powershell Copy-Item from network drives

查看:51
本文介绍了需要有关来自网络驱动器的 Powershell Copy-Item 的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Copy-Item 从远程机器到另一台远程机器的命令:

I am trying to use Copy-Item from remote machine to another remote machine with the command:

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

我不断收到错误找不到路径\\machine1\abc\123\log 1.zip"

我可以访问该路径并从那里手动复制.

I can access that path and copy manually from there.

我以管理员身份打开 PowerCLI 并运行此脚本...我完全被困在这里,不知道如何解决它.

I am opening PowerCLI as administrator and running this script... I am absolutely stuck here and not sure how to resolve it.

推荐答案

这似乎与 PowerShell v3 一样.我没有方便测试的 v2,但是我知道有两个选项应该可以工作.首先,您可以映射 PSDrive:

This seems to work as is on PowerShell v3. I don't have v2 handy to test with, but there are two options that I'm aware of, which ought to work. First, you could map 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

如果这是你要做的很多事情,你甚至可以把它包装在一个函数中:

If this is something you're going to do a lot, you could even wrap this in a function:

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
}

或者,您可以为每个路径明确指定提供者:

Alternately, you can explicitly specify the provider with each path:

Copy-Item -Path "Microsoft.PowerShell.Core\FileSystem::\\machine1\abc\123\log 1.zip" -Destination "Microsoft.PowerShell.Core\FileSystem::\\machine2\\c$\Logs\"

这篇关于需要有关来自网络驱动器的 Powershell Copy-Item 的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆