无法将文件复制到" test-Path"可以看到

时间:2014-03-31 18:38:07

标签: windows powershell

这是我到目前为止所拥有的。我收到了消息

  

Copy-Item:路径中的非法字符。

我正在尝试在每个工作站上创建一个目录(`89),将工作站上的现有文件复制到该文件夹​​,然后将新文件复制到所述路径。当我评论所有与复制有关的事情并且只是验证路径时,路径返回有效。

我尝试使用批处理文件在SCCM(2007)中通过as / w push部署这些文件,但由于找不到路径/无效路径错误而导致失败,因为·(称为中间点)在Trnsport之间。

$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
    }
}

1 个答案:

答案 0 :(得分:2)

发生错误是因为您的目的地不应该有\*。如果没有它,请尝试它,它应该没有问题。

cp -force $file "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS"