forked from dfinke/ImportExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPsGallery.ps1
21 lines (19 loc) · 1.29 KB
/
PsGallery.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$top1000 = foreach ($p in 1..50) {
$c = Invoke-WebRequest -Uri "https://www.powershellgallery.com/packages" -method Post -Body "q=&sortOrder=package-download-count&page=$p"
[regex]::Matches($c.Content,'<table class="width-hundred-percent">.*?</table>', [System.Text.RegularExpressions.RegexOptions]::Singleline) | foreach {
$name = [regex]::Match($_, "(?<=<h1><a href=.*?>).*(?=</a></h1>)").value
$n = [regex]::replace($_,'^.*By:\s*<li role="menuitem">','', [System.Text.RegularExpressions.RegexOptions]::Singleline)
$n = [regex]::replace($n,'</div>.*$','', [System.Text.RegularExpressions.RegexOptions]::Singleline)
$by = [regex]::match($n,'(?<=">).*(?=</a>)').value
$qty = [regex]::match($n,'\S*(?= downloads)').value
[PSCustomObject]@{
Name = $name
by = $by
Downloads = $qty
}
}
}
del "~\Documents\gallery.xlsx"
$pivotdef = New-PivotTableDefinition -PivotTableName 'Summary' -PivotRows by -PivotData @{name="Count"
Downloads="Sum"} -PivotDataToColumn -Activate -ChartType ColumnClustered -PivotNumberFormat '#,###'
$top1000 | export-excel -path '~\Documents\gallery.xlsx' -Numberformat '#,###' -PivotTableDefinition $pivotdef -TableName 'TopDownloads' -Show