windows - 无法将文件复制到 "test-Path"可以看到的路径

标签 windows powershell

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

Copy-Item : Illegal characters in path.

我正在尝试在每个工作站 (`89) 上创建一个目录,将工作站上的现有文件复制到该文件夹​​,然后将新文件复制到指定的路径。当我注释掉与复制有关的所有内容并仅验证路径时,路径返回为有效。

我尝试使用批处理文件在 SCCM (2007) 中通过软件推送部署这些文件,但由于找不到路径/无效路径错误而失败,因为 ·(称为中间点)在 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
    }
}

最佳答案

发生错误是因为您的目的地不应该有 \*。尝试一下,它应该没有问题地完成。

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/

相关文章:

windows - 安装 Alien::XGBoost 库时出错

python - pip 安装失败,显示 "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"

powershell - 管道将 JSON 转换为 ForEach 时的奇怪行为

powershell - Powershell 中的哈希表

xml - Powershell HasChildNodes是否适用于文本?

java - 使用 JSch SFTP 下载文件时获取 "The file does not exist."

python - 如何修复 Python pip install openai 错误 : subprocess-exited-with-error

c - 如何转换文件。 a 到 .c 或其他扩展名?我需要读取文件.a

powershell - 压缩归档命令返回 "Exception: Stream was too long."

powershell 测试路径未被识别为 cmdlet