Calling a function within module / Powershell

powershell

Solution

[Edit] I was not doing a Import Module with a -Force option. The answer below is incorrect, but perhaps the Get-Command forced a refresh? Either way, I'm leaving it for completeness of the experience!

Thanks to latkin for pushing me to another path where i found this:

How do I retrieve command from a module

Not only do you have to import a module, you then have to "get" it as well (?)

Import-Module -Name <ModuleName> 
Get-Command -Module <ModuleName>

After I issued the Get-Command, everything started to work!

Thanks latkin for quick response!

Problem

I must be missing something basic here, but i'm new to powershell... I wrote a function and saved it in a file called "UserSelectionList.psm1", the function is stubbed out like this: ``` function Global:UserSelectionList([String[]] $UserOptions) { ... } ``` i then try to call it with this script: ``` Import-module "l:\support downstream\solarc\cngl\powershell scripts\userselectionlist.psm1" $Options = "a","b","c" cls $result = UserSelectionList $Options echo $result ``` The resulting error is: ``` The term 'UserSelectionList' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:5 char:28 + $result = UserSelectionList <<<< $Options + CategoryInfo : ObjectNotFound: (UserSelectionList:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ``` I'm planning to have more than one function in a module, but this is where I'm at. thanks in advance

Original source

Related problems