PowerShell: Download List of SQL Server MVPs

Turtle Shell?!
Turtle Shell?!

This weekend, I was working on something that I will blog about later this week.  As part of that, though, I needed to download a list of all of the SQL Server MVPs that Microsoft publishes.

A few times back, I just cut-n-pasted these down to get them all out quick and dirty.  After reading John Samson’s (Blog | @JohnSansom) The Best Database Administrators Automate Everything, I figured I would take it to heart.  This time I would automate it with a PowerShell script.

Below is the script I came up with.  It extracts the MVP profile ID and their name and places them in a file at c:tempmvp_import.txt.


$webclient = New-Object system.net.webclient
$file1="c:tempdownload_mvp_html.txt"
$file2="c:tempitem_mvp_html.txt"
$file3="c:tempmvp_import.txt"
Clear-Content $file3
$i = 1
do {
$url="https://mvp.support.microsoft.com/communities/mvp.aspx?product=1&competency=SQL+Server&page=" + $i
$webclient.DownloadFile($url,$file1)


Select-String -path $file1 -Pattern "<a>[A-Z].*?</a>" -AllMatches `
| % { $_.Matches } | % { $_.Value } | set-content $file2


Get-Content $file2 | % {
$_.substring($_.IndexOf('profile=')+8, 36) + "|" + $_.substring($_.IndexOf('"&gt;')+2,$_.IndexOf(': SQL Server')-$_.IndexOf('"&gt;')-2) | add-content $file3
}
$i++
}
while ($i -le 29)

There is probably a quicker method to extract this data, but it works and got me what I needed.