3.6. A Consistent Verb-Noun Naming Scheme

Windows PowerShell cmdlets consistently use a verb-noun (that is a verb followed by a hyphen followed by a noun) naming scheme. For example, to find the running services on a machine, you can type:

get-service

This returns information about all services on the machine (whether they are running or stopped).

As a more complex example, to find the verbs available in the version of PowerShell on your machine, use this command:

get-command -CommandType cmdlet |
group-object verb |
sort-object Count |
format-list Count, Name,Group

Figure 3-24 shows part of the results on the machine I am using to write this book. As you can see, the get verb is frequently used, as are new and set.

Figure 3.24. Figure 3-24

The first step of this example retrieves objects representing all available cmdlets. The second step uses the group-object cmdlet to group the cmdlets by the verb part of the cmdlet name. The third step sorts the groups by the count of the group (in this case the verb). The final step uses the format-list cmdlet to display the count of each group, its name, and the cmdlets in each group.

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.