在远程机器上复制文件的 PowerShell 命令 [英] PowerShell Command to Copy File on Remote Machine
问题描述
我需要使用 PowerShell 将文件从本地机器复制到远程机器.我可以使用以下命令将文件复制到远程计算机:
I have a requirement to copy file from local machine to remote machine using PowerShell. I can copy the file to remote computer using following command:
copy-item -Path d:\Shared\test.txt -Destination \\server1\Shared
以上命令使用网络共享路径复制文件.我不想使用网络共享选项,因为该文件夹不会在远程计算机上共享.我尝试了以下命令但不起作用.
the above command uses network share path to copy the file. I don't want to use network share option as the folder will not be shared on the remote machine. I tried following commands but not working.
copy-item -Path d:\Shared\test.txt -Destination \\server1\c$\Shared
Invoke-Command -ComputerName \\server -ScriptBlock {
copy-item -Path D:\Shared\test.txt -Destination C:\Shared
}
请让我知道如何在不使用 UNC 路径的情况下使其工作.我对远程计算机上的该文件夹拥有完全权限.
Please let me know how to make it working without using UNC path. I have full permissions on that folder on the remote machine.
推荐答案
我找到的最快方法,因为使用的帐户是管理员,是执行以下操作:
Quickest way I found to this, since the account being used is Administrator, is to do the following:
New-PSDrive -Name X -PSProvider FileSystem -Root \\MyRemoteServer\c$\My\Folder\Somewhere\
cd X:\
cp ~\Desktop\MyFile.txt .\
## Important, need to exit out of X:\ for unmouting share
cd c:\
Remove-PSDrive X
每次都有效.
这篇关于在远程机器上复制文件的 PowerShell 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!