2014-06-18 47 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 ...,以確保您傳遞正確的參數。

相關問題