PowerTip: Trace What Loads with a PowerShell Module

PowerTip: Trace What Loads with a PowerShell Module

  • Comments 2
  • Likes

Summary: Use the Verbose switched parameter with the Import-Module cmdlet to trace module load activity.

Hey, Scripting Guy! Question How can you watch what loads when importing a Windows PowerShell module?

Hey, Scripting Guy! Answer Use the Verbose switch when calling the Import-Module cmdlet:

Import-Module psdiagnostics -verbose

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

    thanks for sharing

    here a function to trace module loaded in session:

    Function Trace-Module([switch]$View) {

      $Modules=compare @(powershell -nop -c 'module') @(module) |

           Where { $_.SideIndicator -eq '=>' }

      if($Modules) {

         if($View) {

           $Modules | foreach {

              get-command -Module $_.InputObject |

                  select commandType,Name,ModuleName |  ogv -title "Trace Modules $(date)"

           }

         } else {

           $true

         }

      } else {

         $false

      }

    }

    PS II> trace-Module

    $false

    PS II> ipmo mod2

    PS II> trace-Module

    $true

    PS II> trace-Module -view

  • @Walid Toumi this is a cool function. Well done, thank you for sharing.