簡體   English   中英

如何自動設置 [L] Not to all?

[英]How I can set automatically [L] Not to all?

我的問題是 powershell 7.2 開關 [L] 不是全部

我找到了有關 -confirm 的信息,但沒有幫助我如何將自動 [L] 'Not to all' 設置為 function。 我不會讓用戶輸入。 -Confirm:$false, ConfirmPreference = "None" 或 'Set-ExecutionPolicy Unrestricted' 沒有幫助。 查詢每次都來。 你有一個想法/例子如何將 [L] 設置為自動?

確認問題

$ConfirmPreference=”High” 沒有幫助,因為“High”總是會出現消息。 我坐在 $ConfirmPreference=”None” 一樣。

實際的 cmdlet 是一個 Remove-Item。 是的,我有 testet -Force 和 -Confirm:$false 並且提交總是來的。

powershell 用戶輸入可以模擬嗎? 像這樣?:[System.Windows.Forms.SendKeys]::SendWait("{L}") 在 Z531B84AD41B2A753DA83ACF367990701 中怎么會這樣?

PowerShell 的確認提示並非旨在以編程方式響應; 反而:

  • 要么:用戶應該以交互方式決定。

  • 或者:提示應該被完全抑制暗示一個[A] Yes to All響應),這需要


在您的特定情況下,如果目標目錄為非Remove-Item ,則默認為[L] No to All的等價物是根本不調用 Remove-Item :

# Assume $dir contains the literal directory path of interest.
if (Get-ChildItem -Force -LiteralPath $dir | Select-Object -First 1) {
  Write-Error "Cannot remove directory $dir, because it is not empty."
} 
else {
  Remove-Item -LiteralPath $dir
}

相反,如前所述, Remove-Item -Recurse -LiteralPath $dir將抑制確認提示,但在刪除之前悄悄地 go (暗示[A] Yes to All )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM