如何告诉’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

我需要向命令中添加什么,以便它能够无条件地复制文件?

120631 次浏览

It has a -force parameter.​​​​

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