PowerShell – Yes and No Prompt with If and Else

Note: This is a recovered post from my old blog. See how we recovered these posts using the Wayback Machine and AI tooling.

Prompt the user with a Yes/No dialog and take different actions based on their answer. Useful for interactive PowerShell scripts where you need user confirmation before proceeding with an action.

$Popup = New-Object -ComObject Wscript.Shell
$Answer = $Popup.Popup("Hello User, make a choice", 0, "Title of window",4)
If ($Answer -eq 6) {
    #insert commands that you want to take place if YES is selected
    $Popup.Popup("You Clicked Yes", 0, "YES")
    }
Else {
    #insert commands that you want to take place if NO is selected
    $Popup.Popup("You Clicked NO", 0, "NO")
    }