2014-06-18 42 views
-2

我正在尝试将我制作的屏幕保护程序文件复制到我们的所有桌面和便携式计算机\ system32文件夹中。我创建了一个电脑文本文件,并发现这个脚本,但我不断收到这个错误。任何帮助,将不胜感激。将大量文件复制到域计算机

在作为管理员登录的2012服务器上的Powershell 3.0中运行此操作。

$computers = gc "\\server\share\scripts\computers.txt" 
$source = "\\share\scripts\MySlideshow.scr" 
$dest = "C:\Windows\System32" 
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 given path's format is not supported. 
At C:\users\tech\desktop\scripts\screen.ps1:6 char:9 
+   Copy-Item $source -Destination \\$computer\$dest -Recurse 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [Copy-Item], NotSupportedException 
    + FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.CopyItemCommand 
+0

不应该是'$ source ='\\ server01 \ share \ scripts \ MySlideshow.scr''? – TheMadTechnician

+0

'\\ $ computer \ $ dest'将不起作用,因为它不是有效的路径名。 (如果计算机是'\\ Test',则会导致'\\ Test \ C:\ Windows \ System32',这是非法的。在UNC路径名中不能有嵌入的':'。) –

回答

2

你的目的地产生的UNC格式无效。你传递

"\\computer\c:\windows\system32" 

时,你应该通过

"\\computer\c$\windows\system32" 

尝试引述-destination参数这样太:

Copy-Item $source -Destination "\\$computer\$dest" -Recurse 

您还需要使用单引号时分配给$dest以防止PowerShell尝试将美元符号扩展为变量签名。

$dest = 'c$\windows\system32' 

调试脚本使用copy-item -whatif ...,以确保您传递正确的参数。

相关问题