PowerShell prompt to continue execution of code

I have a script I am using to automate WSUS processes, and the last stage of it goes on to remove all old/unnecessary files/objects.

I would like to prompt 'Press 'Enter' to continue with removal or any other key to stop' before the cleanup stage to give people the option to not run it.

The code I currently have at the end of the script is here:

Get-WsusServer 10.1.1.25 -PortNumber 8530 | Get-WsusUpdate -Classification All -Approval Unapproved -Status FailedOrNeeded | Approve-WsusUpdate -Action Install -Target $ComputerTarget -Verbose

Write-Host "Updates have been approved!"
Write-Host "Preparing to clean WSUS Server of obsolete computers, updates, and content files."

#Part2 - WSUS Server Cleanup

##Run Cleanup Command
Get-WsusServer $WSUS_Server -PortNumber $PortNumber | Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles

Just prior to #Part2 I would like to have the prompt 'Press enter to continue or any other key to abort'

Is there a simple way to do this?

Everything I've seen appears to involve nesting the entire script inside of a code block which I'd rather not do. =/


Another simple solution would be to use:

Read-Host -Prompt "Press any key to continue or CTRL+C to quit" 

I believe this is a better solution to the currently accepted answer because the requirement of hitting enter on the keyboard. I don't believe hitting enter will accept the UI prompt unless that UI element is in focus.


You Can use write-warning option. quite sleek:

Write-Warning "This is only a test warning." -WarningAction Inquire
WARNING: This is only a test warning.
Confirm
Continue with this operation?
 [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"):

Just add -confirm to your Invoke-WsusServerCleanup command. It's built in.