Author Posts

November 3, 2017 at 10:30 pm

I have now successfully converted my script to a module(.psm1), it loads, but immediately gives this error! What am I doing wrong please?

PS 337 D:\Scripts> import-module -name d:\scripts\modules\modem\modem.psm1 -global -force
Calculating total connect time of all GPRS modem devices...
Total online usage since 30/10/2017 is 00:22:00 minutes (5 Mb)

PS 338 D:\Scripts> modem
modem : The term 'modem' 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:1 char:1
+ modem
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (modem:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS 339 D:\Scripts> get-module -name modem

ModuleType Version    Name     ExportedCommands
---------- -------    ----     ----------------
Script     0.0        modem    {AddTime, convert, SubtractTime}

November 3, 2017 at 10:53 pm

You have to pass through till here d:\scripts\modules\modem they try it. You are trying from Scripts folder only. you have to pass modules and modem.

November 3, 2017 at 11:13 pm

I also omitted to wrap the whole script code with

function Get-Modem { #complete existing code }

. Never done this before so I will try again.

November 6, 2017 at 1:26 pm

The purpose of a module is to group functions. When you import your module named 'modem' that makes the functions within it available. Unless you have a function named 'modem' within your module named 'modem' you should get that error. Try running this command to see the available functions in your module then go from there.

get-command -module modem