代码之家  ›  专栏  ›  技术社区  ›  AndreasKnudsen

PowerShell:复制项找不到路径

  •  3
  • AndreasKnudsen  · 技术社区  · 15 年前

    我正在努力 PowerShell 从远程计算机复制文件 AD )到本地计算机。 在最奇怪的地方失败了。下面是一段脚本:

        $configs = Get-ChildItem -Recurse -ErrorAction SilentlyContinue -Filter "*.config" $serverUNCPath 
    foreach($config in $configs){
        $config_target_dir = $dest.Path + $config.Directory.FullName.Replace($serverUNCPath,"")
        if(Test-Path -Path $config_target_dir){
            Copy-Item $config -Destination  $config_target_dir
        }
    }
    

    消息失败了

    Cannot find path 'D:\ServerDeploy\TestMachine1\website\web.config' because it does not exist.
    At :line:39 char:12
    +           Copy-Item <<<<  $config -Destination  $config_target_dir
    

    小径 D:\ServerDeploy\TestMachine1\website 存在。我为此发疯了。

    我能做什么来修复它?

    1 回复  |  直到 15 年前
        1
  •  7
  •   Peter Mortensen icecrime    15 年前

    哎呀…好啊?

    如果我换了线

     Copy-Item $config -Destination  $config_target_dir
    

    具有

     Copy-Item $config.FullName $config_target_dir
    

    它突然神奇地工作了……

    给出了什么?