
Similarly I prefer using functions over loops for failing the validation, as I find the code cleaner and more reusable. By way of personal preference I like using the switch statement for input validation, as I generally find it easier to read and debug than a bunch of if elses and more versatile than a do while. Validating input can be done in several ways. It was too long to put into a comment at the right place. =/īuilding this answer just as a follow-up add-on based on the OPs comment about how to validate input, as an addition to the other good answers. Just prior to #Part2 I would like to have the prompt 'Press enter to continue or any other key to abort'Įverything I've seen appears to involve nesting the entire script inside of a code block which I'd rather not do. Get-WsusServer $WSUS_Server -PortNumber $PortNumber | Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles Write-Host "Preparing to clean WSUS Server of obsolete computers, updates, and content files." 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 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. You’ve got a few different options depending on what you’re asking the user to select from.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.


Sometimes you need to prompt the user to provide some value before you can complete your PowerShell script.
