PowerShell has a list of approved verbs such as Get, New, Test, and so forth. But, what if I wanted to reboot a computer?  Why not name the function "Reboot-Computer"?  What would it break? 

Absolutely nothing.  You can name your functions and scripts anything you want without caring for the established naming conventions.  Those who have to use and/or maintain your code may have choice words for you, but the language itself doesn’t care a whit.

Or does it?

In my (admittedly limited) experience, there is one case where PowerShell raises the most minute of objections.

- You’re writing a library of functions.

- You’re importing it with the Import-Module cmdlet.

- And you’ve given it the proper .psm1 (PowerShell Module) extension.

Then, and only then, PowerShell will complain if you have a function that doesn’t use an approved verb.

WARNING: The names of some imported commands from the module 'foo' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

You can suppress this, but instead of going into that, I'm going to encourage you to use approved verbs.

Import-Module offers a few advantages, and one disadvantage over .-loading the file in terms of managing functions.  Here are the upsides.

  • Get-Command -Module ModuleName will display the functions contained in the module.
  • Get-Command -Name FunctionName will display the hosting module.
  • Get-Module will list which modules you have loaded.  Some are auto-loaded by PowerShell.  The ExportedCommands property is a DataDictionary (read: HashTable) of commands each module loads.  This is handy if you're debugging a script that is importing multiple libraries and you need to see which library has the function in question.

The one downside I've seen is PowerShell being "so smart it's stupid".  If you try to import a module that Get-Module already lists, PowerShell will silently fail.   Use the -Force, Luke.