If you use VSCode for your PowerShell development, you may have noticed the wavy line under the name of your functions. This is VSCode letting you know that your function does not adhere to the approved verb list. The PowerShell team has made a conscious effort to name functions and cmdlets consistently.

  • Verb-Noun.
  • Get-ChildItem
  • Set-ADAccountPassword
  • ConvertTo-Json
  • Export-DbaLogin

What you’re going to do and what you’re going to do it to.

What verbs are approved?! Easily enough, you can use an often overlooked cmdlet that comes with PowerShell called Get-Verb. In 5.1, a list of verbs and the group they are part of is returned. PowerShell 7.x returns the verbs, the letters to start an alias for that verb, the group and a brief description.

 
     
        
Get-Verb # PS 5.1

Verb        Group
----        -----
Add         Common
Clear       Common
Close       Common
Copy        Common
Enter       Common
Exit        Common
...
 
    
 
     
        
Get-Verb # PS 7.x

Verb        AliasPrefix Group          Description
----        ----------- -----          -----------
Add         a           Common         Adds a resource to a container, or attaches an item to another item
Clear       cl          Common         Removes all the resources from a container but does not delete the container
Close       cs          Common         Changes the state of a resource to make it inaccessible, unavailable, or unusable
Copy        cp          Common         Copies a resource to another name or to another container
Enter       et          Common         Specifies an action that allows the user to move into a resource
Exit        ex          Common         Sets the current environment or context to the most recently used context
...

 
    

Using the right verbs for your functions and cmdlets helps other people have an idea about what the intended purpose. If you see Get-DailyRecipe you probably have a good chance of guessing what this does. If you’re looking for the script to reset a password, you can safely skip that one.

Even if you only write code only for yourself, using the right verb is a good habit to get into. How many times have you come back to something a year later and asked yourself “What the heck is fix02.ps1?”. Naming thing consistently helps everyone, including you.

Learn. Grow. Practice responsible naming!