Monthly Archive


Learning PowerShell – 4 friends

When you start learning PowerShell you will find that it has a massive amount of self discovery built into the system. There are four cmdlets you find yourself using all of the time:

  • Get-Help
  • Get-Command
  • Get-Member
  • Get-PSDrive

Oh.  You want to know what they do – try this

"get-help", "get-command", "get-member", "get-psdrive" | 
foreach { Get-Help $_ | select Name, Synopsis | Format-List}

OK this is playing to a certain extent but there are some interesting PowerShell points from this.

We start by creating a list of the cmdlets we want to investigate. These are passed onto the pipeline. Foreach will work with each one of them in turn as it comes along the pipeline. The next very important point is that we have a seperate pipeline within the foreach.

On the inner pipeline we start by using get help with the cmdlet name represented by $_  (you will see a lot of this guy – it represents the object on the pipeline).  We then select the name and the synopsis out of help and use format-list to display.

For detailed investigation of the cmdlets use the full and detailed parameters

Get-Help Get-Command -Detailed
Get-Help Get-Command -Full

Between these four friends you will be able to learn a lot about PowerShell


Technorati Tags: Powershell,Learning

Leave a Reply