3 ms·
> "powershell also kind of has an awful UX, and a serious discoverability problem." There are points of criticism I could level at PowerShell, but discoverabil
by ZenoArrow 9y ago
> "powershell also kind of has an awful UX, and a serious discoverability problem."
There are points of criticism I could level at PowerShell, but discoverability is not one of them.
If you want to explore PowerShell without using any formal tutorials, I'd recommend five commands:
* Get-Verb
* Get-Alias
* Get-Help
* Get-Module
* Get-Command
Get-Verb is useful as it gives you clues about the PowerShell naming convention. Aside from aliases, the vast majority of the commands in PowerShell start with one of the verbs listed by Get-Verb. You can use tab completion to cycle through all currently available commands, e.g. type "Get" (without quotes) then keep pressing the tab key to see the available commands (that are currently loaded).
Get-Alias shows you the command aliases that have been setup for use in your PowerShell session. The reason I recommend it here is twofold:
1. The aliases provided by default are assigned to the most commonly used commands, so Get-Alias can give you a shortlist of commands that are good to explore first.
2. If you have prior experience with the Windows command line or the Linux terminal, Get-Alias will give you clues about what different commands do. For example, dir and ls are both aliases for Get-ChildItem.
Get-Help gives you access to command documentation. One hint I'd give about help in PowerShell is if you need to update the PowerShell help available on your machine, run Update-Help from an elevated command prompt (e.g. on Windows, run PowerShell as an administrator before running Update-Help). If you haven't got local admin permissions, Get-Help is still useful, and will point you in the direction of relevant online documentation if it can't find the help documentation locally.
Get-Module lists the commands by the module they're found in. By default it only shows the modules that are currently loaded, but with Get-Module -ListAvailable you can see all the modules you can choose from. In later versions of PowerShell running a command automatically loads the module it's in (in earlier versions you have to use Load-Module beforehand if the module wasn't already loaded). Note that the -ListAvailable option could've been discovered using Get-Help (e.g. Get-Help Get-Module).
Get-Command allows you to explore the metadata about a command. You're better off reading up on what it can do (Get-Help Get-Command would be a decent start), but to give you one example of why you might find it useful when starting out is that it lets you explore the parameter sets associated with a command. Parameter sets are ways of allowing different groups of parameters to be used with a single command. For example, if you're testing the network connection of computers on a work network, you may choose to reference the computer by IP address, or you may reference the computer by computer name. In this case, parameter sets are a way of making one of those parameters mandatory. Note that commands have a default parameter set, and if you try running a command with mandatory parameters in the default parameter set without passing them in, it will request the minimum information the command requires to function. With all that said, I'd leave Get-Command alone until you're more familiar with the basic operations in PowerShell.
As a final piece of advice, if you're on Windows I would recommend using PowerShell ISE when you start out. It might not look as pretty as VS Code (which also has decent PowerShell support), but it's good at exposing what you need to write effective PowerShell scripts. I use it regularly at work, even for simple tasks that the standalone PowerShell command line would work for. Also worth noting that it ships with Windows, simply search for PowerShell ISE using the Windows menu search.
- Already__Taken 9y agoMore subtle discoverability point; Go log onto your production box and use get-whatever the hell you want. There is nothing you can do wrong if you stick to get- while learning. That really encourages users to open the console and have a go.