我想了解在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
标志的回答?
感谢您的快速回复和解决方法。 :) –