84

The following PowerShell script works if the resources are not there.

  Copy-Item $src_dir $dst_dir$agent_folder -recurse

But if the resources are there, it 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 have to add to the command so that it will unconditionally copy the files?

2 Answers 2

171

It has a -force parameter.​​​​

19

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
1
  • 4
    I guess false means param not mandatory and False means the default value is $false Jul 21, 2015 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.