Created
May 3, 2018 21:59
-
-
Save loic-sharma/1b4f48168f7f4a040722a68d00c37908 to your computer and use it in GitHub Desktop.
Script to find all packages that depend on a specific package
This file contains hidden or 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
$package = 'Newtonsoft.Json' | |
$connection = "TODO..." | |
$done = @() | |
$todo = @($package.ToLowerInvariant()) | |
while ($todo.Count -gt 0) { | |
$next = $todo | Select-Object -First 50 | |
$nextIn = [string]::Join(',', @($next | % { "'$($_)'" })) | |
$query = "SELECT DISTINCT(r.[Id]) | |
FROM [dbo].[PackageDependencies] d | |
INNER JOIN [Packages] p ON p.[Key] = d.[PackageKey] | |
INNER JOIN [PackageRegistrations] r ON r.[Key] = p.[PackageRegistrationKey] | |
WHERE d.[Id] IN ($($nextIn))" | |
$results = Invoke-Sqlcmd -Query $query -ConnectionString $connection | |
$results | % { | |
$id = $_.Id.ToLowerInvariant() | |
if ($todo -notcontains $id -and $done -notcontains $id) { | |
Write-Host "Found new dependent package: $($id)" | |
$todo += @($id) | |
} | |
} | |
$todo = @($todo | ? { $next -notcontains $_ }) | |
$done += @($next) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment