Skip to content

Instantly share code, notes, and snippets.

@brimur
Last active August 24, 2022 20:14
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brimur/724cdae0ecddbd6ac5b9b58b47cd65d9 to your computer and use it in GitHub Desktop.
Save brimur/724cdae0ecddbd6ac5b9b58b47cd65d9 to your computer and use it in GitHub Desktop.
Dynamic map of Microsoft SKU to friendly name
##################################################################
#
# Requires Windows PowerShell v2 - v5
# Will not work in PS 7+ due to lack of ParsedHtml functionality
#
##################################################################
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$skuPage = Invoke-WebRequest "https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/licensing-service-plan-reference"
# Extract the sku table from the sku page
$skuTable = @($skuPage.ParsedHtml.getElementsByTagName("TABLE"))[0]
$headers = @()
$tableRows = @($skuTable.Rows)
$SkuList = @{}
$ti = (Get-Culture).TextInfo
# For each html row in the html table
foreach($row in $tableRows)
{
$cells = @($row.Cells)
# If we've found a table header, remember its headers
if($cells[0].tagName -eq "TH")
{
$headers = @($cells | % { ("" + $_.InnerText).Trim() })
continue
}
# Find headers
$license = [Ordered] @{}
for($i = 0; $i -lt $cells.Count; $i++)
{
$header = $headers[$i]
if(-not $header) { continue }
$license[$header] = ("" + $cells[$i].InnerText).Trim()
}
# Add license to hashtable using the string id and converting the product name to capitalised first letter for better presentation
$SkuList[$license."String ID"] = $ti.ToTitleCase(($license."Product name").ToLower())
}
@zaicnupagadi
Copy link

zaicnupagadi commented Jul 21, 2022

Great! Thank you for that, I was trying to get this based on what user has assigned, but still it was not as nice name as in the Office Portal, I haven't known about that one! - https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/licensing-service-plan-reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment