I recently found myself on a long bus ride with my laptop and no Internet connection. I decided to create a PowerShell puzzle for myself to keep me busy until I reached my destination. It ended up being kind of interesting so I wanted to share my puzzle and the solution with here.
Challenge
PowerShell has the concept of “Get-*” cmdlets where these will only retrieve information but will never change anything. This makes Get commands safe to run, even if you don’t know what they do. PowerShell ships with hundreds of Get cmdlets. It would be great to know what kind of information each one provided. To do that I’d need to run every Get command. That’s simple enough but is complicated by the fact that most Get- cmdlets come with multiple ‘parameter sets’ and many are configured with mandatory parameters. This means that if we blindly run each command we’ll end up with a bunch of errors and prompts for user input.
So what we need to do is figure out which of the Get- commands can be run without passing any parameters. We then also want to exclude commands that run properly but don’t return any data by default.
Solution
Check out the script below. It will scan the system for every Get- command and then will figure out which ones can be executed directly without parameters and will actually return data. It then runs all of those and returns the first 5 objects so you can get a feel for what kind of data is returned. It will then display a report showing how many cmdlets met each criteria. On my system for example we can see that 143 commands can be executed and return something useful just by typing the name of the command and hitting enter.