With PowerShell V2, if you try to import cmdlets or modules that violates the verb naming convention, you’ll get a warning. Here’s an example module to demonstrate this. First, I create the file testmodule.psm1. I store this as testmodule.psm1, inside my modules folder:
- # Demo of badly named function
- # and how PowerShell V2 deals with it
- function badly-named {
- "Inside the badly named function"
- }
- }
PSH [C:\foo]: ls $Modules\testmoduleSs you can see, you can create a module with a badly named function just as you can create your own badly named cmdlets – and they work. But when you try to import such a module, PowerShelL v2 emits a warning error.
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users\tfl\Documents\WindowsPowerShell\Modules\testmodule
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 1/2/2010 12:36 PM 340 testmodule.psm1
PSH [C:\foo]: import-module testmodule -verbose
VERBOSE: The command name 'badly-named' includes an unapproved verb which might make it less discoverable
VERBOSE: Importing function 'badly-named'.
PSH [C:\foo]: badly-named
Inside the badly named function
So for those of you getting into PowerShell, make sure that the functions you are putting into modules are named correctly!
No comments:
Post a Comment