Created
October 24, 2017 16:28
-
-
Save tomasr/d4f2ed79caa857ab0e58a34e28e5541a to your computer and use it in GitHub Desktop.
Sample script to json-scrape support site for KB titles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$source = Import-CSV ".\hotfixesAll.csv" | |
$knownHotfixes = @{} | |
function Get-HotfixUrl($hotfixId) { | |
$id = $hotfixId | |
if ($hotfixId.StartsWith('KB')) { | |
$id = $hotfixId.Substring(2) | |
} | |
return "https://support.microsoft.com/app/content/api/content/help/en-us/$id" | |
} | |
function Get-HotfixTitleFromUrl($url) { | |
$html = Invoke-WebRequest -Uri $url -Method GET | |
$json = ConvertFrom-Json $html | |
return $json.details.heading | |
} | |
function Get-HotfixTitle($hotfixId) { | |
if ($knownHotfixes.ContainsKey($hotfixId) ) { | |
return $knownHotfixes[$hotfixId] | |
} | |
$url = Get-HotfixUrl $hotfixId | |
$title = Get-HotfixTitleFromUrl $url | |
if (![String]::IsNullOrEmpty($title)) { | |
$knownHotfixes[$hotfixId] = $title | |
} | |
return $title | |
} | |
foreach ($hf in $source) { | |
$title = Get-HotfixTitle $hf.HotfixID | |
$hf | Add-Member -MemberType NoteProperty -Name Title -Value $title | |
} | |
$source | Export-CSV .\hotfixesWithTitle.csv -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it seems that the link return "https://support.microsoft.com/app/content/api/content/help/en-us/$id" is dead :-(
Any idea what is the new link?