A series of tutorials, or How To Get Started With PowerShell: “It’s Awesome” edition.
The title was originally built around “Teach A Man A Cmdlet and he PowerShells for a day; Teach a Man to Use Get-Command and he PowerShell’s for a lifetime.” But it got more and more clumsy and convoluted so I finally decided that there really was a limit to my own cleverness.
PowerShell really is quite clever though and makes it really easy to work out the cmdlets you want to use for any task.
Get-Command is used to get, well, commands. As long as you know a word or two of the command you want you can use it to get what you want.
PowerShell commands always have the format [VERB]-[DESCRIPTION] and common verbs are GET, SET, ADD and REMOVE.
So let’s say I wanted to get the size of one of my physical disks. I can use wildcards in Get-Command to work out what I need;
Get-PhysicalDisk looks to be the one. And that returns all my disks;
I can use wildcards again to get just the one I’m interested in too;
That shows me the size of the disk. But that only summarizes a few bits of information about the disk. If I wanted it all I could pipe the output to Format-List (which gives us everything);
Pretty cool!
If I then wanted to work out how to make some changes on my Physical Disk I could use Get-Help to get the information on the Set-PhysicalDisk cmdlet (remembering that Set- was a common verb to make changes to an object).
From that I’d probably look at a few examples;
PowerShell is designed to make people coming from other systems feel at home. A lot of commands have aliases to commands used in other shells. If you’re familiar with DOS you can just use DOS commands;
But using Get-Alias you can work out what the “real” command is under the hood and use that;
And it’ll give similar results if you’re used to other shells too;
You can also use Get-Member to work out what you can do to an object too;