What To Do / Not to Do in PowerShell: Part 10

Here's why it's important to give your scripts and functions the same kinds of names as a native cmdlet.

Don Jones

July 21, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Whenever you're writing a script, function, or even an advanced function, you should give those things a cmdlet-style name, consisting of a Verb-SingularNoun. You get to make up your SingularNoun, but the Verb should come fromthis list at Microsoft (scroll down to see the 7 Verbs catagories, and click on one to see its verbs).

Why?

Consistency. As an admin, I know what a Get cmdlet does. I know what to expect from Invoke, Write, Out, Format, Export, Set, New, and so forth. Throw me some weird verb like "instantiate" and I'll have no clue what to expect. I won't be able to discover that cmdlet on my own, either, because it doesn't have one of the standard verbs.

Consistency in cmdlet names (as well as parameter names) is a key to helping people use your command more easily and effectively. 

What's more, you shoudl get in the habit of appending some company-level prefix to your nouns. Work for Boeing? Maybe your cmdlet names should look like "Get-BngUser" so that there's less chance of them ever conflicting with someone else's cmdlet names. Oh, and never use the "PS" prefix - that's reserved for the PowerShell team at Microsoft.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like