Home Best Practice Functions Pick Good Function Names

Pick Good Function Names

Functions are self-defined cmdlets, so function names should adhere to the same strict conventions. While you are free to name your functions any way you like, it is best practice to use the very same Verb-Noun syntax used by cmdlets – at least for functions that are publicly exposed.

Using Verb-Noun Syntax

A function name should start with an approved verb. Do not use any verb. Instead, stick to the verbs found in the list provided by Get-Verb:

PS> Get–Verb

Verb                                               Group                                           
––––                                               –––––                                           
Add                                                Common                                          
Clear                                              Common                                          
Close                                              Common                                          
Copy                                               Common                                          
Enter                                              Common                                          
Exit                                               Common                                          
Find                                               Common                                          
Format                                             Common                                          
Get                                                Common                                          
Hide                                               Common                                          
Join                                               Common                                          
Lock                                               Common                                          
Move                                               Common                                          
New                                                Common                                          
Open                                               Common                                          
Optimize                                           Common                                          
Pop                                                Common                                          
Push                                               Common                                          
Redo                                               Common                                          
Remove                                             Common                                          
Rename                                             Common                                          
Reset                                              Common                                          
Resize                                             Common                                          
Search                                             Common                                          
Select                                             Common                                          
Set                                                Common                                          
Show                                               Common                                          
Skip                                               Common                                          
Split                                              Common                                          
Step                                               Common                                          
Switch                                             Common                                          
Undo                                               Common                                          
Unlock                                             Common                                          
Watch                                              Common                                          
Backup                                             Data                                            
Checkpoint                                         Data                                            
Compare                                            Data                                            
Compress                                           Data                                            
Convert                                            Data                                            
ConvertFrom                                        Data                                            
ConvertTo                                          Data                                            
Dismount                                           Data                                            
Edit                                               Data                                            
Expand                                             Data                                            
Export                                             Data                                            
Group                                              Data                                            
Import                                             Data                                            
Initialize                                         Data                                            
Limit                                              Data                                            
Merge                                              Data                                            
Mount                                              Data                                            
Out                                                Data                                            
Publish                                            Data                                            
Restore                                            Data                                            
Save                                               Data                                            
Sync                                               Data                                            
Unpublish                                          Data                                            
Update                                             Data                                            
Approve                                            Lifecycle                                       
Assert                                             Lifecycle                                       
Complete                                           Lifecycle                                       
Confirm                                            Lifecycle                                       
Deny                                               Lifecycle                                       
Disable                                            Lifecycle                                       
Enable                                             Lifecycle                                       
Install                                            Lifecycle                                       
Invoke                                             Lifecycle                                       
Register                                           Lifecycle                                       
Request                                            Lifecycle                                       
Restart                                            Lifecycle                                       
Resume                                             Lifecycle                                       
Start                                              Lifecycle                                       
Stop                                               Lifecycle                                       
Submit                                             Lifecycle                                       
Suspend                                            Lifecycle                                       
Uninstall                                          Lifecycle                                       
Unregister                                         Lifecycle                                       
Wait                                               Lifecycle                                       
Debug                                              Diagnostic                                      
Measure                                            Diagnostic                                      
Ping                                               Diagnostic                                      
Repair                                             Diagnostic                                      
Resolve                                            Diagnostic                                      
Test                                               Diagnostic                                      
Trace                                              Diagnostic                                      
Connect                                            Communications                                  
Disconnect                                         Communications                                  
Read                                               Communications                                  
Receive                                            Communications                                  
Send                                               Communications                                  
Write                                              Communications                                  
Block                                              Security                                        
Grant                                              Security                                        
Protect                                            Security                                        
Revoke                                             Security                                        
Unblock                                            Security                                        
Unprotect                                          Security                                        
Use                                                Other                                           


  Use one of the officially approved verbs

So instead of naming your function "Create-Account", choose "New-Account".

To quickly check whether a verb is really an approved verb, again use Get-Verb. If Get-Verb returns nothing, then you know the verb you tested is not approved:

PS> Get–Verb create

PS> Get–Verb new

Verb                                               Group                                           
––––                                               –––––                                           
New                                                Common                                          


  The verb "create" is not approved, the verb "new" is approved

If you do not use an approved verb, or abandon Verb-Noun-Syntax altogether, as soon as you distribute your functions as a PowerShell module, you will get a warning message whenever this module is imported:

PS> Import–Module LabHelper
WARNING: The names of some imported commands from the module 'labhelper' include unapproved verbs tha
t might make them less discoverable. To find the commands with unapproved verbs, run the Import–Modul
e command again with the Verbose parameter. For a list of approved verbs, type Get–Verb.


  This module contains functions or cmdlets with unapproved verbs

You can override this message by supplying the parameter -DisableNameChecking, but a much better approach is to make sure you are using approved verbs – approved verbs are an important measure to keep cmdlets and functions consistent and easily discoverable.

PS> Import–Module LabHelper –DisableNameChecking


Using a Good Noun

Next, pick a good noun that describes the topic your function deals with. There is no "approved list" for nouns, so you can freely pick a noun. However, a good noun should be English and singular. Use singular nouns even if your function returns multiple objects.

So instead of "New-Accounts", name your function "New-Account".

Using Correct Casing

Function names are case-insensitive. Still, you should use upper case initials for both verb and noun. This makes function names more readible, and also when you autocomplete function names, the casing you choose is applied to autocompleted text.

Using a Company Prefix

There are chances that you are not the only one that picked a particular function name. To make sure there is no risk of conflicting function names, especially when you plan to distribute functions inside a PowerShell module, you or your company should early on pick a company-wide prefix, typically two or three characters.

So instead of naming your function "New-Account", when your company name is "My IT Services", a good prefix could be "MIS", and your function name should be "New-MISAccount". With a prefix, there is a much lower chance of conflicts, and also you can easily identify your own functions from other functions.