Powershell Best Practice #6: Use singular noun for cmdlet (not plural noun)

By | May 22, 2015

Best Practice: It is recommended to use an English singular noun for cmdlet, do not use plural noun.

Explanation:

PowerShell cmdlets use the syntax Verb-Noun.
Example: GetService (“Get” is the verb, “Service” is the noun).

Following this syntax convention makes more intuitive what the scope of the cmdlet.
(ex: with Get-Service, we know that the cmdlet is related with services).

It is useful for users to read, use and discover cmdlets, for example:

  • Add-Member
  • Clear-Item
  • Compare-Object
  • Get-ADUser
  • Import-Module
  • Move-ADObject

You should choose an English noun (instead of Spanish, French, German, etc.) as English is the most used language in IT.
Having your scripts with English names will be easier for other people to work with.

Here are some examples using cmdlets in another languages:

  • ZiskejtePocitace (Czech)
  • ZiskejteUzivatele (Czech)

As you can see, if we don’t use the standard convention it can be difficult to understand.
Be sure to not pick up a noun already used by a native cmdlet, use the parameter -Noun to check.

get-command-noun

If you think the noun you choose could conflict with a native cmdlet, you should use a prefix.
For example, the ActiveDirectory module adds the prefix “AD” for cmdlets: Get-ADUser, Get-ADComputer, etc.


previous-buttonnext-button

Leave a Reply

Your email address will not be published.