2011-01-20 27 views
22

我運行下面的命令:自動確認

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」 ?

回答

16

嘗試使用Remove-Item上的-Force參數。

+0

作品完美...謝謝! – siliconpi 2011-01-21 03:06:28

+0

對我不起作用:( 刪除項目iis:$ IISSitePath -Force – smnbss 2011-12-09 18:30:12

+2

@smnbss add -recurse到您的remove-item命令 – 2015-01-23 15:12:31

24

添加確認:$ false來取消確認。

+1

這不會起作用-Confirm用於強制確認,關閉它只是運行正常決定邏輯 – JasonMArcher 2011-01-22 00:22:24

8

添加-recurse刪除項目後,也強制參數,有助於消除隱藏文件 例如爲:

GCI C: 「SVN」 \ TEMP \ -exclude *的.svn基,-recurse | %{ri $ _ -force -recurse}

22

默認爲:無提示。

您可以-confirm:$false

-confirm禁用它啓用它。然而,它仍然會提示,當目標:

  • 是一個目錄
  • 這是不爲空
  • and the -recurse參數未指定。

概括起來:

Remove-Item -recurse -force -confirm:$false 

...應涵蓋所有情形。

0

您只需要在該行後面添加一個/A即可。

例子:

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