Discover the Easy Way to Begin Learning Windows PowerShell

Discover the Easy Way to Begin Learning Windows PowerShell

  • Comments 2
  • Likes

Summary: Microsoft Scripting Guy, Ed Wilson, looks at Windows PowerShell naming conventions to simplify learning Windows PowerShell.

Hey, Scripting Guy! Question Hey, Scripting Guy! I have a feeling that I am quickly falling behind the Windows PowerShell wave. I am an Exchange Server admin where I work, and we are planning our deployment of Exchange Server 2010. I was searching for information when I ran across some of your blogs about using Windows PowerShell with Exchange Server 2010. I quickly realized that I do not know very much about Windows PowerShell. Here is the problem, it seems like everyone else in the world knows way more about Windows PowerShell than I do. I know that when Windows Server “8” Beta ships, there will be even another version of Windows PowerShell. So should I wait until Windows Server “8” Beta and then learn the new Windows PowerShell, or should I begin learning the current version of Windows PowerShell?

—GB

Hey, Scripting Guy! Answer Hello GB,

Microsoft Scripting Guy, Ed Wilson, is here. The other night, the Scripting Wife and I had dinner with Brian who is a member of the Charlotte Windows PowerShell User Group. In addition to answering lots of questions about Windows PowerShell and providing a decent amount of career guidance, the conversation also lingered for a while about tea. I thought about writing a blog called The Fundamentals of Tea—and I might do so on my personal blog. The problem is how does one describe the taste of Earl Gray tea to someone who has never tasted it before? Perhaps the best thing is to teach someone how to properly brew a nice cup of tea, and then allow them to taste some of my favorite teas. After all, there are literally hundreds of teas in the world, but they generally fall into just a few tea families. As you experience the flavors, you can find the types of tea that interest you.

GB, the situation with learning Windows PowerShell is similar to learning about the world of tea. There are a few basic things you need to learn. A little grouping can be done to aid with the different types of Windows PowerShell cmdlets, and then from there, the process is one of exploring where your interests lie.

Windows PowerShell cmdlet naming helps you learn

One of the great things about Windows PowerShell is the verb-noun naming convention. In Windows PowerShell, the verbs indicate an action to perform, such as Set to make a change or Get to retrieve a value. The noun indicates the item with which to work such as a process or a service. By mastering the verb-noun naming convention, you can quickly hypothesize what a prospective command might be called. For example, if you need to obtain information about a process, and you know that Windows PowerShell uses the verb Get  to retrieve information, you surmise that the command might very well be Get-Process. To obtain information about services you try Get-Service…and once again you are correct.

Note   When “guessing” Windows PowerShell cmdlet names, always try the singular form first. Windows PowerShell prefers the singular form of nouns. It is not a design requirement, but it is a strong preference. Therefore, the cmdlets are named Get-Service, Get-Process, not Get-Services or Get-Processes.

To see the list of approved verbs, use the Get-Verb cmdlet. This is shown here.

Image of command output

There are nearly 100 approved verbs in Windows PowerShell 2.0. This is shown in the command that follows where the Measure-Object cmdlet returns the count of verbs.

PS C:\> (get-verb | Measure-Object).count

96

Analyzing Windows PowerShell verb grouping

With nearly 100 verbs, you may be asking yourself, “How does an array of 100 verbs assist in learning Windows PowerShell?” You would be justified in asking that question. Nearly 100 different and unrelated items are really difficult to learn. However, the Windows PowerShell team grouped the verbs. For example, analyzing the common verbs reveals a pattern. The common verbs are listed here.

PS C:\> Get-Verb | where { $_.group -match 'common'} | Format-Wide verb -AutoSize

Add     Clear  Close  Copy   Enter  Exit   Find   Format Get    Hide   Join   Lock

Move    New    Open   Pop    Push   Redo   Remove Rename Reset  Search Select Set

Show    Skip   Split  Step   Switch Undo   Unlock Watch

The pattern for the verbs emerges when you analyze the verbs, for example: Add/Remove, Enter/Exit, Get/Set, Select/Skip, Lock/Unlock, Push/Pop, and so on. By learning the pattern to the common verbs, you quickly gain a handle on the Windows PowerShell naming convention.

By using the Windows PowerShell verb grouping, you can determine where to focus your efforts. The following command lists the Windows PowerShell verb grouping.

PS C:\> Get-Verb | select group -Unique

 

Group

-----

Common

Data

Lifecycle

Diagnostic

Communications

Security

Other

Analyzing Windows PowerShell verb distribution

Another way to get a better handle on the Windows PowerShell cmdlets is to analyze the verb distribution. Although there are nearly 100 approved verbs (not to mention unapproved verbs that are used by rogue developers), only a fraction of them are utilized repeatedly, and some of them are not used at all in a standard Windows PowerShell installation. By using the Group-Object (group is an alias) and the Sort-Object cmdlets (sort is an alias), the distribution of the cmdlets quickly becomes evident. The following command shows the verb distribution.

Get-Command -CommandType cmdlet | group verb | sort count –Descending

The command and the output associated with the command are shown in the image that follows.

Image of command output

The preceding output makes it clear that most cmdlets only use a few of the verbs. In fact, most of the cmdlets use one of only 10 verbs. This is shown here.

PS C:\> Get-Command -CommandType cmdlet | group verb | sort count -Descending | selec

t -First 10

 

Count Name                      Group

----- ----                      -----

   46 Get                       {Get-Acl, Get-Alias, Get-AuthenticodeSignature, G...

   19 Set                       {Set-Acl, Set-Alias, Set-AuthenticodeSignature, S...

   17 New                       {New-Alias, New-Event, New-EventLog, New-Item...}

   14 Remove                    {Remove-Computer, Remove-Event, Remove-EventLog, ...

    8 Export                    {Export-Alias, Export-Clixml, Export-Console, Exp...

    8 Write                     {Write-Debug, Write-Error, Write-EventLog, Write-...

    7 Import                    {Import-Alias, Import-Clixml, Import-Counter, Imp...

    7 Out                       {Out-Default, Out-File, Out-GridView, Out-Host...}

    6 Add                       {Add-Computer, Add-Content, Add-History, Add-Memb...

    6 Start                     {Start-Job, Start-Process, Start-Service, Start-S...

In fact, of 236 cmdlets, 138 of the cmdlets use one of only 10 different verbs. This is shown here.

PS C:\> (Get-Command -CommandType cmdlet | measure).count

236

PS C:\> $count = 0 ; Get-Command -CommandType cmdlet | group verb | sort count -Descending |

select -First 10 | % {$count += $_.count ; $count}

46

65

82

96

104

112

119

126

132

138

Therefore, GB, all you need to do is to master 10 verbs and you will have a good handle on more than half of the cmdlets that ship with Windows PowerShell 2.0. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi Ed,

    a good intro into the world of powershell cmdlets!

    I'm afraid version 3 will add some new cmdlets but more than that the available modules will add a lot of functionality to it ...

    One thing, I would change to "138 of the cmdlets use one of only 10 different verbs."

    Get-Command -CommandType cmdlet | group verb | sort count -Descending | select -First 10 | %{ $count=0 } { $count += $_.count } { $count }

    Klaus.

  • @K_Schulte Thank you. Yes, PowerShell v.3 brings in a lot of new cmdlets and learning how to find stuff will be a crucial skill. You are also correct, I "fudged" a bit with my 10 verbs thing ... Thanks for keeping me on track. Also, Teresa and I hope you are doing well.