Skip to content

Instantly share code, notes, and snippets.

@HeyItsGilbert
Last active May 22, 2025 01:09
Show Gist options
  • Save HeyItsGilbert/f3599ed8b52996319e831575decd05af to your computer and use it in GitHub Desktop.
Save HeyItsGilbert/f3599ed8b52996319e831575decd05af to your computer and use it in GitHub Desktop.
param(
[int]$Limit
)
$modules = Get-Module -ListAvailable
$finalList = @()
$hash = @{
'Errbody' = @()
}
foreach($module in $modules){
$root, $name = $module.Name -split '[.]'
if(-not [String]::IsNullOrEmpty($name)){
if(-not $hash.ContainsKey($root)){
$hash[$root] = @()
}
$hash[$root] += $module
} else {
$finalList += $module
}
$subList = @()
$hash.GetEnumerator() | %{
if ($_.Value.Count -ge $Limit){
$finalList += $_.Key
} else {
# If the count was less then the limit, toss them all back in
$finalList += $_.Value
}
}
# Finally print the list
$finalList | Sort-Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment