powershell中自动确认删除
我正在运行以下命令:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
默认为:无提示。
您可以使用
-Confirm
启用它,或使用-Confirm:$false
禁用它>但当目标:
-Recurse
参数时,仍然会提示。还需要
-Force
来删除隐藏和只读项目等。总结一下:
...应该涵盖所有场景。
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:
-Recurse
parameter is not specified.-Force
is required to also remove hidden and read-only items etc.To sum it up:
...should cover all scenarios.
添加 -confirm:$false 以抑制确认。
Add -confirm:$false to suppress confirmation.
尝试在
Remove-Item
上使用-Force
参数。Try using the
-Force
parameter onRemove-Item
.在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}
只是一个额外的提示:
假设 PS1 (helloworld.ps1) 有如下代码:
如果我们期望每次运行代码时,它都会自动运行 Set-ExecutionPolicy,而不提示用户&默默地运行代码...
这样是行不通的!我仍在研究如何在不提示用户的情况下运行 PS 代码如果我发现的话会发布解决方案
Just an additional tip:
Let's say the PS1 (helloworld.ps1) has a code like below:
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
您只需在该行后面添加一个
/A
即可。例子:
You just need to add a
/A
behind the line.Example: