Cách yêu cầu Copy-Item 'PowerShell' sao chép tệp vô điều kiện


82

Tập lệnh PowerShell sau sẽ hoạt động nếu tài nguyên không có ở đó.

  Copy-Item $src_dir $dst_dir$agent_folder -recurse

Nhưng nếu các tài nguyên ở đó, nó sẽ nói:

+   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

Tôi phải thêm gì vào lệnh để nó sao chép tệp vô điều kiện?

Câu trả lời:



19

Từ tài liệu ( 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

4
Tôi đoán có nghĩa là sai param không bắt buộc và các phương tiện False giá trị mặc định là $ false
fredericrous
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.