Copy-Item with over write

powershell

Solution

Are you using the quotes correctly?

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

Problem

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.

Original source