使用Powershell从远程PC读取和写入共享网络

时间:2018-12-17 14:28:04

标签: powershell

我试图从远程计算机读取文件,然后将读取的内容写入网络中的共享文件夹中。这是我的代码。

Write-Host "Remote copy a file" 
$username = 'Usuario' 
$password = 'Password' 

$myfile = [System.IO.File]::ReadAllBytes("C:\user.txt") ;
$Escribir={[System.IO.File]::WriteAllBytes("\\192.x.x.x\foreach\54.txt", $args)} ;
$pw = ConvertTo-SecureString $password -AsPlainText -Force 
$cred = New-Object Management.Automation.PSCredential ($username, $pw) 
$servers = Get-Content C:\Users\Agent\Desktop\pcs
foreach($server in $servers) { 
$s = New-PSSession -computerName $server -credential $cred 
Write-Host "PC name: $server ..." -ForegroundColor GREEN -Background BLACK

$Job = Invoke-Command -Session $s -ArgumentList $myfile -ScriptBlock $Escribir -AsJob
    $Null = Wait-Job -Job $Job

Write-Host "Completed" 
Remove-PSSession -Session $s 
} 

运行.ps1文件时,出现以下错误。

Error

0 个答案:

没有答案