如何告诉“PowerShell”复制项目无条件复制文件

如果资源不存在,以下PowerShell脚本将起作用。

Copy-Item $src_dir $dst_dir$agent_folder -recurse 

但是,如果资源在那里,它会说:

 + 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 

我必须添加什么命令才能无条件复制文件?

它有一个-force参数。

从文档( 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