我想了解在Powershell cmdlet中$?
和$lastexitcode
變量與-Confirm
標誌之間的關係。在PowerShell中使用-Confirm
說,例如,您運行-confirm
一個命令時,它會相應提示你行動:
PS C:\temp> rm .\foo.txt -confirm
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove Directory" on target "C:\temp\foo.txt".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):n
PS C:\temp> $?
True
據我所知,技術上的命令成功運行,但如果用戶選擇了不那麼該命令沒有運行。
我的問題是我如何獲得用戶對-Confirm
標誌的回答?
感謝您的快速回復和解決方法。 :) –