Created
March 4, 2022 13:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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