Simple module dependency mapper

Script to list module dependencies

function Get-Depends { [CmdLetBinding()] Param( $ModulePath, $ModuleName, $Depth = 0, [switch]$ReturnDependency ) if ($Depth -eq 0) { $RootModulePath = $ModulePath } If ($Depth -ge 8 ) { Throw ‘Module dependency is deeper than 8 levels, possible cyclical dependency’ } try { Write-Verbose -Message $($('–' * $Depth)+$ModuleName) $ModPath = $(($(Get-ChildItem -Path “$($ModulePath)” -Filter “$ModuleName.psd1” -Recurse ) |Where-Object -FilterScript { $($.Directory | Split-Path -Leaf) -match $ModuleName }))
$Dependencies = Test-ModuleManifest -Path $(Get-ChildItem -Path “$($ModPath.DirectoryName)” -Filter “$ModuleName.psd1” -Recurse | Select-Object -ExpandProperty Fullname) -ErrorAction Stop -Verbose:$false | Where-Object -FilterScript { $
.RequiredModules }| Select-Object -ExpandProperty RequiredModules

    if($Dependencies)
    {
        $Dependencies | ForEach-Object -Process {
            $Mod = "$($_.Name)"
            #Write-verbose $ModulePath
            $ModPath = $(($(Get-ChildItem -Path $RootModulePath -Filter "$Mod.psd1" -Recurse ) |Where-Object  -FilterScript {
                        $($_.Directory | Split-Path -Leaf)  -match $Mod
            })) 
            
            Get-Depends -ModulePath "$($ModPath.DirectoryName)" -ModuleName $Mod -Depth ($Depth+1) 
        }

        If ($ReturnDependency) 
        {
            Return $Dependencies
        }
    }
}
catch
{
    $_
}

}

Get-ChildItem -Path C:\temp\azurePS -Directory | ForEach-Object -Process { “rn” Get-Depends -ModulePath C:\temp\azurePS -ModuleName $_.basename -Verbose -ReturnDependency }

Will get the dependencies of a specific module

Get-Depends -ModulePath C:\temp\azurePS -ModuleName AzureRM.Storage -Verbose

VERBOSE: AzureRM.StreamAnalytics
VERBOSE: –AzureRM.Profile

VERBOSE: AzureRM.Tags
VERBOSE: –AzureRM.Profile

VERBOSE: AzureRM.TrafficManager
VERBOSE: –AzureRM.Profile

VERBOSE: AzureRM.UsageAggregates
VERBOSE: –AzureRM.Profile

VERBOSE: AzureRM.Websites
VERBOSE: –AzureRM.Profile

comments powered by Disqus