Skip to content

Instantly share code, notes, and snippets.

@ChrisLGardner
Forked from Jaykul/Trace-Dependency.ps1
Created September 13, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisLGardner/3eb1096f140659c460f2a441423de3a2 to your computer and use it in GitHub Desktop.
Save ChrisLGardner/3eb1096f140659c460f2a441423de3a2 to your computer and use it in GitHub Desktop.
Extract module dependency information from a script. **Note**: will show errors for commands not available on your system.
#requires -Module Reflection
function Find-Dependencies {
param($Path)
Get-ParseResults $Path |
Find-Token { $_ -is "System.Management.Automation.Language.CommandAst" } |
Get-Command -Name { $_.CommandElements[0].Value } -ea continue | # Errors will appear for commands you don't have available
Sort Source, Name |
Group Source |
Select @{N="Module";e={$_.Name}}, @{N="Used Commands";E={$_.Group}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment