Previously, any time I wanted to validate input in PowerShell, I’d write custom validation functionality per-script. It turns out that I reuse the same basic methods though, so I’ve created and shared a generalised function!
This prompts users to enter input that matches a displayed list, then returns their input if successful. This works from VM or object selection, to simple y/n acceptance restrictions.
The full details and code are here: https://github.com/GSGBen/powershell/blob/master/Read-ValidInput.psm1
To make it accessible to your code save it somewhere then use import-module <path to above file>

Videogames
Hey, do you like videogames? If so, please check out my game Inventor Simulator on Steam, and consider adding it to your wishlist. Craft inventions and sell them to customers, then automate your workbench, workshop and store! Research new inventions or create your own from scratch. Set prices based on an economic model, unlock and craft upgrades, and vertically integrate your supply chain. Become the world's greatest inventor!See full gameplay on Steam!