Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-CommandDependencies {
- [CmdletBinding(DefaultParameterSetName="ScriptDependencies")]
- param(
- [Parameter(ParameterSetName="ScriptDependencies", Mandatory=$true)]
- [String]$ScriptPath,
- [Parameter(ParameterSetName="FunctionDependencies", Mandatory=$true)]
- [String]$FunctionName
- )
- if ($PsCmdlet.ParameterSetName -eq "ScriptDependencies")
- {
- if( -not (Test-Path $ScriptPath)){
- throw "Script file $ScriptPath not found"
- } else {
- $definition = Get-Content -Path $ScriptPath -Delimiter "`0"
- }
- }
- else
- {
- if( -not (Test-Path function:\$FunctionName)){
- throw "Function $FunctionName not found"
- } else {
- $scriptBlock = Get-Content -Path function:\$FunctionName
- $definition = $scriptBlock.ToString()
- }
- }
- [System.Management.Automation.PSParser]::Tokenize($definition,[ref]$null) |
- Where-Object -FilterScript {$_.Type -eq "Command"} |
- Select-Object -ExpandProperty Content |
- Sort-Object -Unique |
- Get-Command -ErrorAction SilentlyContinue
- }
Advertisement
Add Comment
Please, Sign In to add comment