Successfully imported module listed in Get-Module but not running

This topic contains 3 replies, has 3 voices, and was last updated by  Jeremy Murrah 1 week, 4 days ago.

  • Author
    Posts
  • #83614

    Derf User
    Participant

    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}
  • #83617

    Sunilkatke
    Participant

    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.

  • #83621

    Derf User
    Participant

    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.

  • #83669

    Jeremy Murrah
    Participant

    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
    

You must be logged in to reply to this topic.