简体   繁体   中英

How to force the copy of a file using powershell

I'm using powershell to copy file to a remote computer witht he following command :

Copy-Item -Path [MyPath]\* -Destination \\[server]\[MyPath] -force

It's working great, but sometime I'm receiving the following error message: "The process cannot access the file [...] because it is being used by another process.".

Is it possible to force the file to be copy even if it's in use?

The only way to do that is to get rid of the handle the process has to the file you are overwriting.

It's either a service or a desktop application accessing the file. You can find out what has access to the file using handle.exe from SysInternals .

Once you know what is accessing the file you can stop/kill it remotely (assuming you have permissions to do so).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM