AndreasKnudsen
AndreasKnudsen

Reputation: 3481

PowerShell: Copy-Item Cannot find path

I'm trying to get PowerShell to copy files from a remote computer (on which I have admin rights through AD) to the local computer. It fails in the strangest place. Here's a snippet of the script:

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

It fails with the message

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

The path D:\ServerDeploy\TestMachine1\website exists. I'm going mad over this.

What can I do to fix it?

Upvotes: 6

Views: 25255

Answers (2)

Marvin Xu
Marvin Xu

Reputation: 369

In my case, it turns out to be a case sensitivity issue. My source path is in WSL which is case sensitive.

Upvotes: 0

AndreasKnudsen
AndreasKnudsen

Reputation: 3481

Eeeeh.... OK?

If I replaced the line

 Copy-Item $config -Destination  $config_target_dir

with

 Copy-Item $config.FullName $config_target_dir

it suddenly magically worked....

What gives?

Upvotes: 11

Related Questions