【问题标题】:How to use Remove-Item -Confirm:$false -Force properly in Windows PowerShell如何在 Windows PowerShell 中正确使用 Remove-Item -Confirm:$false -Force
【发布时间】:2021-09-10 12:40:18
【问题描述】:

所以,我在 PowerShell 中编写此脚本,我需要在 Windows 上删除 APPDATA 中的一些文件。我写了这行代码,它并没有默默地删除该项目。即使在使用 $Confirm:false 之后,它也会要求确认。我该如何解决这个问题?

我的代码:

Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Confirm:$false -Force

每次我运行脚本时都会收到这个不需要的确认框:

【问题讨论】:

  • 因为您尝试删除的项目中包含子项目,您需要在-Force 之后提供-Recurse 开关,这将允许您在没有提示的情况下删除子项目
  • 这行得通。谢谢

标签: windows powershell powershell-2.0 powershell-3.0 powershell-4.0


【解决方案1】:

这是您修改后的代码。我希望它对你有用。

Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Recurse -Force

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 1970-01-01
    • 2021-10-20
    • 2014-08-30
    • 2020-11-17
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 2021-08-15
    相关资源
    最近更新 更多