How to specify "Copy-PowerShell Element" for error-free copying of files

The following PowerShell script works if there are no resources there.

Copy-Item $src_dir $dst_dir$agent_folder -recurse 

But if there are resources, he will say:

 + Copy-Item <<<< $src_dir $dst_dir$agent_folder -recurse + CategoryInfo : ResourceExists: (C:\Users\Pac\Desktop\Agents\Agent0\lib:S tring) [Copy-Item], IOException + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.CopyItemComm and 

What do I need to add to the command so that it accurately copies files?

+49
powershell
Nov 24 '09 at 4:43
source share
2 answers

It has the -force .

+114
Nov 24 '09 at 4:47
source share
— -

From the documentation ( help copy-item -full ):

 -force <SwitchParameter> Allows cmdlet to override restrictions such as renaming existing files as long as security is not compromised. Required? false Position? named Default value False Accept pipeline input? false Accept wildcard characters? false 
+16
Nov 24 '09 at 4:48
source share



All Articles