Skip to content

Instantly share code, notes, and snippets.

@rifatx
Created March 4, 2022 13:48
Show Gist options
  • Save rifatx/db155ce3384dd5764b8e44c8908c9340 to your computer and use it in GitHub Desktop.
Save rifatx/db155ce3384dd5764b8e44c8908c9340 to your computer and use it in GitHub Desktop.
PowerShell script to list assemblies that has a reference to another assembly with given pattern
$basePath = "\\some\source\directory"
$sourceFilePattern1 = "FilePattern1.*.dll"
$sourceFilePattern2 = "FilePattern1.*.dll"
$referenceName = "ReferencePattern"
Get-ChildItem -Path $basePath -Directory |
ForEach-Object {
$path = [System.IO.Path]::Combine($basePath, $_.Name, "*")
Get-ChildItem -Path $path -Include $sourceFilePattern1, $sourceFilePattern2 |
Foreach-Object {
try {
$asm = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($_.FullName)
$references = $asm.GetReferencedAssemblies()
$res = $references | Where-Object {
$_.Name.Contains($referenceName)
}
if ($res.Count -gt 0){
$asm.Location | Write-Host
}
}
catch {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment