PowerShell - 将一个计算机文本文件复制到另一台计算机

时间:2016-01-22 19:39:18

标签: powershell remote-server file-copying

在同一个域名[domain.net]上我有两台电脑。 第一台计算机有一个测试恶意软件文本文件,该文件保存在我的防病毒Symantec [由于权限等]不可见的位置。

我想要做的是从第一台计算机[运行程序时我当前登录的计算机]复制文件,然后将文件复制到我未登录的另一台计算机上。 [目的是测试100多台PC上的防病毒保护监控]

当我尝试以下代码时,我收到错误:

[pc#] Connecting to remote server failed with the following error message : The WinRM client cannot complete the operation within the time specified. Check if the machine name is valid and is reachable over the network and firewall exception for Windows Remote Management service is enabled. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken

我的代码如下:

$Username = "domain.net\usernameID"
$Password = get-content "C:\Users\usernameID\Documents\passwordhash.txt" | convertto-securestring

$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$Password

Invoke-Command -ComputerName PC# -Credential $mySecureCreds -ScriptBlock {
Copy-Item -Path "C:\ProgramData\MalFolder\MalwareTest.txt" -Destination "\\domain.net\c$\Desktop\" -Recurse
}

无论如何都可以绕过此问题,而无需更改防火墙以允许远程处理[总体上不希望出于安全目的]?

或者我这样做的方式不正确?

*******************************************************************

我也尝试过:

Invoke-Command -ComputerName PC# -Credential $mySecureCreds -ScriptBlock {
Copy-Item -Path "C:\ProgramData\MalFolder\MalwareTest.txt" -Destination "C:\Users\usernameID\Desktop\"
}

但得到同样的错误。

也尝试过:

$computers = "PC#"
# This is the directory you want to copy to the computer (IE. c:\folder_to_be_copied) 
$source = "C:\ProgramData\MalFolder\MalwareTest.txt"
# On the desination computer, where do you want the folder to be copied? 
$dest = "c$" 
foreach ($computer in $computers) { 
if (test-Connection -Cn $computer -quiet) { 
    Copy-Item $source -Destination \\$computer\$dest -Recurse 
} else { 
    "$computer is not online" 
} 

}

但得到错误:

Copy-Item : The specified network name is no longer available.

参考:http://www.signalwarrant.com/2012/10/04/copy-a-folder-and-files-to-multiple-computers-powershell/

0 个答案:

没有答案