Skip to content

Instantly share code, notes, and snippets.

@domkirby
Last active January 17, 2025 16:03
Show Gist options
  • Save domkirby/9f7c6d8f49b6ad7029e71bf33bc6e462 to your computer and use it in GitHub Desktop.
Save domkirby/9f7c6d8f49b6ad7029e71bf33bc6e462 to your computer and use it in GitHub Desktop.
Fetches a list of Microsoft SKUs to enable part number translation to product names
function Fetch-MicrosoftSkuList {
$csvUrl = 'https://download.microsoft.com/download/e/3/e/e3e9faf2-f28b-490a-9ada-c6089a1fc5b0/Product%20names%20and%20service%20plan%20identifiers%20for%20licensing.csv'
# The csvUrl will likely need to be updated from time to time.
try {
$csvContent =Invoke-WebRequest -Uri $csvUrl
$csvData = $csvContent | ConvertFrom-Csv
$skuLookup = @{}
foreach ($row in $csvData) {
$skuPartNumber = $row.'String_Id';
$productName = $row.'???Product_Display_Name'; #Weird bug where we get ??? on this column
$skuLookup[$skuPartNumber] = $productName
}
return $skuLookup
} catch {
Write-Warning "An error occurred while fetching the Microsoft SKU list: $_"
return $null
}
}
function Convert-SkuToName {
param (
[Parameter(Mandatory = $true)]
[string]$SkuPartNumber,
[Parameter(Mandatory = $true)]
[hashtable]$SkuLookup
)
if ($SkuLookup.ContainsKey($SkuPartNumber)) {
return $SkuLookup[$SkuPartNumber]
} else {
$return = "Unknown($SkuPartNumber)"
return $return;
}
}
#Example Use (Fetch the sku list)
Write-Progress -Activity "Building the SKU table" -Status "Please wait..." -PercentComplete 50;
$skuLookupIndex = Fetch-MicrosoftSkuList
Write-Progress -Activity "Building the SKU table" -Status "SKU table built successfully." -Completed;
if($skuLookupIndex.Count -ne 0) {
$skuCount = $skuLookupIndex.Count;
Write-Host "SKU table built successfully. With $skuCount SKUs." -ForegroundColor Green;
} else {
Write-Host "Failed to build SKU table. We will not be able to check licensing on this round." -ForegroundColor Red;
pause;
}
#Example use, part number to name
$licensedProduct = Convert-SkuToName -SkuPartNumber "SPB" -SkuLookup $skuLookupIndex #Microsoft 365 Business Premium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment