powershell中自动确认删除

发布于 2024-10-13 11:21:16 字数 487 浏览 2 评论 0原文

我正在运行以下命令:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname}

它经常像这样提示我:

Confirm
The item at C:\temp\f\a\d has children and the Recurse parameter was not specified. If you continue,
all children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): 

如何将其自动设置为“A”?

I'm running the following command:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname}

Which prompts me very frequently like this:

Confirm
The item at C:\temp\f\a\d has children and the Recurse parameter was not specified. If you continue,
all children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): 

How can I have it automatically set to "A"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

疾风者 2024-10-20 11:21:16

默认为:无提示。

您可以使用 -Confirm 启用它,或使用 -Confirm:$false禁用它>

但当目标:

  • 是目录
  • 不为空
  • 未指定-Recurse参数时,仍然会提示。

还需要 -Force 来删除隐藏和只读项目等。

总结一下:

Remove-Item -Recurse -Force -Confirm:$false

...应该涵盖所有场景。

The default is: no prompt.

You can enable it with -Confirm or disable it with -Confirm:$false

However, it will still prompt, when the target:

  • is a directory
  • and it is not empty
  • and the -Recurse parameter is not specified.

-Force is required to also remove hidden and read-only items etc.

To sum it up:

Remove-Item -Recurse -Force -Confirm:$false

...should cover all scenarios.

带上头具痛哭 2024-10-20 11:21:16

添加 -confirm:$false 以抑制确认。

Add -confirm:$false to suppress confirmation.

红墙和绿瓦 2024-10-20 11:21:16

尝试在 Remove-Item 上使用 -Force 参数。

Try using the -Force parameter on Remove-Item.

淡紫姑娘! 2024-10-20 11:21:16

在remove-item后面添加-recurse,-force参数也有助于删除隐藏文件
例如:

gci C:\temp\ -exclude *.svn-base,".svn" -recurse | %{ri $_ -force -recurse}

Add -recurse after the remove-item, also the -force parameter helps remove hidden files
e.g.:

gci C:\temp\ -exclude *.svn-base,".svn" -recurse | %{ri $_ -force -recurse}

┈┾☆殇 2024-10-20 11:21:16
Remove-Item .\foldertodelete -Force -Recurse
Remove-Item .\foldertodelete -Force -Recurse
心病无药医 2024-10-20 11:21:16

只是一个额外的提示:
假设 PS1 (helloworld.ps1) 有如下代码:

Set-ExecutionPolicy Unrestricted -Confirm:$false -Force
Write-Host "Hello, World!"

如果我们期望每次运行代码时,它都会自动运行 Set-ExecutionPolicy,而不提示用户&默默地运行代码...

这样是行不通的!我仍在研究如何在不提示用户的情况下运行 PS 代码如果我发现的话会发布解决方案

Just an additional tip:
Let's say the PS1 (helloworld.ps1) has a code like below:

Set-ExecutionPolicy Unrestricted -Confirm:$false -Force
Write-Host "Hello, World!"

And if we expect that each time the code runs, it would automatically run the Set-ExecutionPolicy without prompting the user & run the code silently...

It won't work that way!! I'm still figuring out how to run a PS code without prompting the user & will post the solution if I find out

风轻花落早 2024-10-20 11:21:16

您只需在该行后面添加一个 /A 即可。

例子:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname} /a

You just need to add a /A behind the line.

Example:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname} /a
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文