PowerTip: Load PowerShell Modules and See What’s Imported

PowerTip: Load PowerShell Modules and See What’s Imported

  • Comments 3
  • Likes

Summary: Learn to parse load information about modules to see what’s imported.

Hey, Scripting Guy! Question How can I analyze what is imported when a Windows PowerShell module loads?

Hey, Scripting Guy! Answer Use the –Verbose switch when importing the module, and redirect the verbose stream to a
          text file so you can use Windows PowerShell cmdlets to parse the file. In the following example,
          all modules are loaded, verbose output is redirected to a file, and Select-String is used to parse
          the file (gmo is an alias for Get-Module and ipmo is an alias for Import-Module):

gmo -l | ipmo -Verbose | 4>>c:\fso\modload.txt

$a = Get-Content C:\fso\modload.txt

$a | Select-String "importing"

$a | Select-String "alias"

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 4 do?

  • It is one of the built-in output streams - see http://technet.microsoft.com/en-us/library/hh847746.aspx.

    4>>c:\fso\modload.txt redirects verbose output to the named file.

  • Shouldn't the command be used without the last pipeline, like this: gmo -l | ipmo -Verbose 4>>c:\fso\modload.txt

    If used like this gmo -l | ipmo -Verbose | 4>>c:\fso\modload.txt you'll get the following error:

    >> : The term '>>' 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:42
    + Get-Module -l | Import-Module -Verbose | >>C:\Users\rehnmni\Desktop\testi.txt
    + ~~
    + CategoryInfo : ObjectNotFound: (>>:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException