这是我目前所拥有的。我收到消息
Copy-Item : Illegal characters in path.
我正在尝试在每个工作站 (`89) 上创建一个目录,将工作站上的现有文件复制到该文件夹,然后将新文件复制到指定的路径。当我注释掉与复制有关的所有内容并仅验证路径时,路径返回为有效。
我尝试使用批处理文件在 SCCM (2007) 中通过软件推送部署这些文件,但由于找不到路径/无效路径错误而失败,因为 ·
(称为中间点)在 Trns
和 port
之间。
$file = "\\path\to\files\ITClientBuild\Specs2\specslas5\testcopy.txt"
$outfile = "c:\temp\las6copy.csv"
gc c:\temp\las6.txt | %{
$computer = $_
$ping = Test-Connection $computer -Count 2 -Quiet
if ($ping) {
$pathTest1 = Test-Path "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS"
$pathTest2 = Test-Path "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS"
if($pathTest1 -eq $true){
# md -Force "\\$computer\c$\windows\temp\las5a"
# cp -force "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS\las6cust.pbd" "\\$computer\c$\windows\temp\las5\*"
cp -force $file "\\$computer\\c$\\Program Files\\AASHTOWare\\Trns·port Client-Server PES-LAS\\*"
"$computer FILE PUSHED to PES-LAS dir" >> $outfile
} else {
"$computer las6 PATH DOES NOT EXIST!!" >> $outfile
}
if ($pathTest2 -eq $true){
# md -Force "\\$computer\c$\windows\temp\las5a"
# cp -force "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS\las6cust.pbd" "\\$computer\c$\windows\temp\las5\*"
cp -force $file "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS\*"
"$computer FILE PUSHED to PES-LAS dir" >> $outfile
} else {
"$computer PES-LAS PATH DOES NOT EXIST!!" >> $outfile
}
} else {
"$computer OFFLINE" >> $outfile
}
}
最佳答案
发生错误是因为您的目的地不应该有 \*
。尝试一下,它应该没有问题地完成。
cp -force $file "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS"
关于windows - 无法将文件复制到 "test-Path"可以看到的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22769533/