powershell - 使用 powershell 从远程 PC 读取和写入共享网络
问题描述
我正在尝试从远程计算机读取文件,然后将读取的内容写入网络中的共享文件夹中。这是我的代码。
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 文件时,出现以下错误。
解决方案
推荐阅读
- javascript - 在 React Native 中将 API 响应数据添加到之前的 AsyncStorage 数据中
- python - DAG runtime error with creating Airflow.cfg file
- mysql - Why Liquibase docker container can't connect to Mysql docker container?
- android - Why getItemCount() called multiple times in recycleView?
- multithreading - Flutter : Function need to wait
- scala - 通过简单的 akka-http 路由测试与演员陷入无限循环
- flutter - 用户做某事时如何更新状态?
- firebase - 从应用程序内打开的firebase动态链接
- c++ - 主数据集为空时更新 VCL TClientDataSet(详细集)
- swift - 无法将类型“(Int)-> Bool”的值转换为预期的条件类型“Bool”,并且在范围内找不到 x