Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created May 3, 2018 21:59
Show Gist options
  • Save loic-sharma/1b4f48168f7f4a040722a68d00c37908 to your computer and use it in GitHub Desktop.
Save loic-sharma/1b4f48168f7f4a040722a68d00c37908 to your computer and use it in GitHub Desktop.
Script to find all packages that depend on a specific package
$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