I am trying to display promp for a user action, and if no action has been taken, the prompt to close and the script continue. here is my configuraiton command line dialog
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","" $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","" $cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel","" $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no,$cancel) $caption = "Caption message here" $dialogmessage = ("Do you want to do something?:`n") $timer =
I looked up and down the internet. I saw how this is implemented in C #, but for life I can not determine the best approach for powershell. I would appreciate any help.
thanks
Edit: Thanks, Noah, here is the updated code, it's even more compact!
$prompt = new-object -comobject wscript.shell $answer = $prompt.popup(("Do you want to do something?`n",5,"title",3) if($answer -eq 6) {Write-Host "Yes was selected"} if($answer -eq 7) {Write-Host "No was selected"} if($answer -eq -1) {Write-Host "Timed out} if($answer -eq 2) {Write-Host "Canceled by user.";exit}
source share