Prompt user to continue or stop the execution of powershell script

Hi,

I’m trying to put a condition in my script to prompt the user to continue or stop the execution.
I have used read-host cmdlet, it asks for user input and two tabs ‘Ok’ and ‘Cancel’. If i press Ok the script execution continues and if i click on Cancel, execution stops at that point but i believe that i not the purpose of read-host ( i expects an input from user ). Is there any cmdlet or procedure to prompt the user to just stop or continue the execution of powershell script.

Please let me know , thanks in advance

Does the cmdlet you using have a -Confirm parameter?

if so you could use that

It will ask for confirmation to proceed

However it only works for a cmdlet & won’t break you out of the script
if you are responding to an error look at the Inquire option on -ErrorAction parameter

If the user will be running from powershell version 3 or greater the pause command is back and it works. However it didn’t exist in PowerShell Version 1 or 2

if ($PSVersionTable.PSVersion.Major -ge 3) {Get-Command Pause}

also. . .
http://blogs.technet.com/b/heyscriptingguy/archive/2013/09/14/powertip-use-powershell-to-wait-for-a-key-press.aspx

-VERN

You might want to look at the definition of the pause command

Read-Host ‘Press Enter to continue…’ | Out-Null

Its not really that different to what you were doing.

The more things change the more they stay the same

Thanks Richard I will look again. Last time I tried using that method to pause a script in PS v2 it continued after a few seconds.