PowerShell custom provider RemoveItem

巧了我就是萌 提交于 2019-12-06 07:10:49

Ultimately if you're asked to remove a container then it is inherently recursive unless the container doesn't contain other containers. I believe PowerShell prompts because the action affects more than the user might initially be aware of (all the container's contents) and warrants confirmation. So in this case, I think the -recurse is used to tell PowerShell "I know what I'm doing".

Where -recurse makes more sense is if you were to execute something like this:

Remove-Item *.bak -recurse

In this case, you want to recursively search for files to delete. Unfortunately the Recurse parameter on Remove-Item is broken for this usage - from the docs:

Because the Recurse parameter in this cmdlet is faulty, the command uses the Get-Childitem cmdlet to get the desired files, and it uses the pipeline operator to pass them to the Remove-Item cmdlet.

So the way to do this currently is:

Get-ChildItem . -r *.bak | Remove-Item

You can suppress the question by setting $ConfirmPreference="None"

http://blogs.msdn.com/b/powershell/archive/2006/12/15/confirmpreference.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!