Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make a PSobject showing published modules and their download count by author

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading