Rajiv
Rajiv

Reputation: 685

Copy-Item with over write

In one of my script, it tries to copy an exe to C:\Windows\Temp folder. For example:

Copy-Item repo\filename.exe -Destination \\$machine_name\C$\Windows\Temp

Error Message:

Copy-Item : The network path was not found.
At D:\CMPortal\Scripts\ClientRepair\RepairCCMClient.ps1:122 char:33
+                     if(Copy-Item <<<<  cmsetup.exe -Destination \\$install_cmexec\C$\Windows\Temp)
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand

When I run the same command manually, it works. Dont know whats wrong. Is there any to overwrite the file if the copying file exists in the destination?

Thanks in advance.

Upvotes: 3

Views: 5651

Answers (2)

E.V.I.L.
E.V.I.L.

Reputation: 2166

Are you using the quotes correctly?

Copy-Item 'repo\filename.exe' -Destination "\\$machine_name\C`$\Windows\Temp" -Force

Upvotes: 4

Shay Levy
Shay Levy

Reputation: 126732

Does $install_cmexec contains a server name? Also, make sure the user who runs the script has the appropriate permissions on the target path.

Upvotes: 1

Related Questions