While I did write something that managed to work 99% of the time someone knows how to do it better than me
I am just looking to learn how to improve my code
$mymods = @()
Find-Module | Where-Object { $_.Author -eq 'NAME' } | %{$mymods = ($_).name}
$dlCount = @()
$mymods | %{((find-module $_).additionalmetadata).downloadCount} | %{$dlCount = $_}
[int]$max = $mymods.count
if ([int]$dlCount.count -gt [int]$mymods.count) {$max = $dlCount.Count}
$results = for( $i = 0; $i -lt $max; $i )
{
Write-Verbose "$($mymods),$($dlCount)"
[PSCustomObject]@{
Modules = $mymods[$i]
Count = $dlCount[$i]
}
}
$results
CodePudding user response:
You can simply do:
Find-Module |
Select Name,Author,@{N="DownloadCount";E={$_.AdditionalMetadata.downloadCount}}
or:
$Modules | Group Author,{$_.AdditionalMetadata.downloadCount}
I suggest you to first save the results of
Find-Module
To a variable and use it each time instead of loading it every request, will perform faster$Modules = Find-Module