SoftwareSavant
SoftwareSavant

Reputation: 9737

Powershell not copying files and not throwing exception

I am not understanding what is happening.

I am attempting to copy and paste dll's from one directory and another.

gci -path $FromPath -Include ("*.dll", "*.pdp") | ? {$_.Name -match "appMaskA|appMaskB|appMaskC"} | foreach{Copy-item $_.Fullname -destination $ToPath -force}

Now that command works for one function that I have it in, but not for this one...

Now, this command is moving dll's to a different server. Not certain why it isn't working.

And if it isn't working it should throw an exception. I did wrap that command in a try catch by the way? Should I be catching a specific exception?

Upvotes: 0

Views: 509

Answers (3)

larsgregersen
larsgregersen

Reputation: 171

Maybe this works for you:

gci -path $FromPath -Include *.dll,*.pdp | where {$_.Name -match "appMaskA|appMaskB|appMaskC"} | Copy-item -path $_ -destination $ToPath -force

For complicated and/or large copying jobs I would use the program robocopy. Robocopy is part of Windows. Execute this command to verify its location:

Get-Command robocopy|select path

Upvotes: 0

Raf
Raf

Reputation: 10097

What does your $ToPath look like? If your code is wrapped in try/catch add -ErrorAction Stop parameter to your copy statement as the default value is to continue so the catch block will never be executed.

gci -path $FromPath -Include ("*.dll", "*.pdp") | ? {$_.Name -match "appMaskA|appMaskB|appMaskC"} | foreach{Copy-item $_.Fullname -destination $ToPath -force -ErrorAction Stop}

Upvotes: 1

Steve Church
Steve Church

Reputation: 344

Does this need to be Powershell or can you use XCOPY via a BASH/CLI script. Using XCOPY you can access C Drive by doing

SERVER.DOMAIN.LOCAL/c$/path/to/dll

Upvotes: 0

Related Questions