2015-06-24 34 views
0

我想将文件夹复制到局域网上的一系列计算机上。以下是我迄今为止:将文件夹复制到局域网上的一系列计算机

$Computers = "Get-Content C:\Scripts\computers.txt" 

$Source = "C:\Install\9_10_00_08HotFix_201504140001" 
$Destination = "\\192.168.6.$\c$\Install" 

ForEach-Object { 
    Copy-Item -Path $Source -Recurse -Destination $Destination -Verbose -Force -ErrorAction SilentlyContinue 
} 
+0

什么不行?你遇到了什么错误? – JAL

回答

0

你没有说你的实际问题是什么,但它可能是你在Get-Content声明错位的第一个双引号,你不能定义一个变量目的地像你一样,并且你对computers.txt中的任何内容(尝试)都没有做任何事情。

更改此:

$Computers = "Get-Content C:\Scripts\computers.txt" 

$Source = "C:\Install\9_10_00_08HotFix_201504140001" 
$Destination = "\\192.168.6.$\c$\Install" 

ForEach-Object { 
    Copy-Item -Path $Source -Recurse -Destination $Destination -Verbose -Force -ErrorAction SilentlyContinue 
} 

到这一点:

$Computers = Get-Content "C:\Scripts\computers.txt" 

$Source = "C:\Install\9_10_00_08HotFix_201504140001" 

$Computers | ForEach-Object { 
    Copy-Item -Path $Source -Recurse -Destination "\\192.168.6.$_\c$\Install" -Verbose -Force -ErrorAction SilentlyContinue 
} 

和你的代码应该工作。

+0

我将其更改为您指定的内容并运行脚本并获得了Copy-Item:找不到网络路径 在C:\ Install \ CopyToNetwork.ps1:6 char:3 + Copy-Item -Path $ Source -Recurse -Destination“\\ 192.168.6。$ _ \ c $ \ In ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 +分类信息: Item],IOException + FullyQualifiedErrorId:System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand –

+0

@alexolynyk检查'$ _'的值并确认具有该IP地址的主机实际上正在运行,启用了管理共享,共享访问不会被Windows防火墙阻止,并且您的帐户有权访问该主机上的管理共享。 –

相关问题