Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[CmdletBinding()]
param(
[string]$AssemblyName,
[string]$Path
)
function Get-AssemblyReverseReferences {
param(
[string]$Name,
[string]$Path = '.'
)
Get-Assemblies $Path |
ForEach-Object {
$reference = $_.References | Where-Object { $_.Name -eq $Name } | Select-Object -First 1
if ($reference) {
[PSCustomObject]@{
AssemblyFile = $_.AssemblyFile
Reference = $reference
}
}
}
}
function Get-Assemblies {
param($Path)
Get-ChildItem -Path $Path -Recurse -Filter '*.dll' | ForEach-Object {
try {
$asm = Get-Assembly $_.FullName
@{
AssemblyFile = $_
References = $asm.GetReferencedAssemblies() | Sort-Object -Property Name
}
}
catch [BadImageFormatException] {
}
catch [IO.FileLoadException] {
}
catch [Security.SecurityException] {
}
}
}
function Get-Assembly {
[OutputType([System.Reflection.Assembly])]
param($Path)
$fileName = Resolve-Path $Path
[System.Reflection.Assembly]::LoadFile($fileName)
}
Get-AssemblyReverseReferences -Name $AssemblyName -Path $Path |
ForEach-Object { [PSCustomObject]@{
Dll = (Resolve-Path -Relative $_.AssemblyFile.FullName)
Reference = $_.Reference
}} |
Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.