ConvertOfficeSKU.psm1
|
function Convert-OfficeSku { <# .SYNOPSIS Convert SKU to Friendly Name. .DESCRIPTION Convert Office SKU IDs to friendly names based on the Microsoft License Service Plan Reference. Supports exact and wildcard matching for ProductName searches. .LINK .Linkedin: https://www.linkedin.com/in/erickvtorres/ .GitHub: https://github.com/erickvtorres .Reference: https://learn.microsoft.com/en-us/entra/identity/users/licensing-service-plan-reference .NOTES .Creator: Erick Torres do Vale .Contact: ericktorres@hotmail.com.br .Date: 2023-09-13 .LastUpdate: 2026-04-07 .Version: 1.0.3 .PARAMETER All List all licenses available. .PARAMETER SkuPartNumber Convert license from SkuPartNumber (exact match). Alias: AccountSkuID. Matches the SkuPartNumber property returned by Get-MgSubscribedSku. .PARAMETER FriendlyName Convert license from FriendlyName. Supports wildcards (e.g. '*365 E*'). .PARAMETER SkuId Convert license from SkuId GUID (exact match). Alias: Guid. Matches the SkuId property returned by Get-MgSubscribedSku. .PARAMETER UpdateMsftDocs Check if the Microsoft documentation has been updated since the last module sync. .EXAMPLE Convert-OfficeSku -All .EXAMPLE Convert-OfficeSku -SkuPartNumber SPE_E3,SPE_E5 FriendlyName SkuPartNumber SkuId ------------ ------------- ----- Microsoft 365 E3 SPE_E3 05e9a617-0261-4cee-bb44-138d3ef5d965 Microsoft 365 E5 SPE_E5 06ebc4ee-1bb5-47dd-8120-11324bc54e06 .EXAMPLE # Pipeline from Get-MgSubscribedSku using SkuPartNumber (Get-MgSubscribedSku).SkuPartNumber | Convert-OfficeSku .EXAMPLE # Pipeline from Get-MgSubscribedSku using SkuId (GUID) (Get-MgSubscribedSku).SkuId | Convert-OfficeSku -SkuId .EXAMPLE Convert-OfficeSku -SkuId 05e9a617-0261-4cee-bb44-138d3ef5d965 FriendlyName SkuPartNumber SkuId ------------ ------------- ----- Microsoft 365 E3 SPE_E3 05e9a617-0261-4cee-bb44-138d3ef5d965 .EXAMPLE Convert-OfficeSku -FriendlyName '*Copilot*' (Returns all licenses with "Copilot" in the friendly name) #> [CmdletBinding(DefaultParameterSetName = 'SkuPartNumber')] param ( [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'SkuPartNumber')] [Alias('AccountSkuID')] [array]$SkuPartNumber, [Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = 'FriendlyName')] [array]$FriendlyName, [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'SkuId')] [Alias('Guid')] [array]$SkuId, [Parameter(Mandatory = $false, ParameterSetName = 'All')] [switch]$All, [Parameter(Mandatory = $false)] [switch]$UpdateMsftDocs ) begin { try { $List = Import-Csv -Path (Join-Path $PSScriptRoot 'LicNames.csv') } catch { Write-Error -Message 'LicNames.csv not found. Ensure the file exists alongside the module.' return } } process { switch ($PSBoundParameters.Keys) { SkuPartNumber { $SkuPartNumber | ForEach-Object { $Name = $_ $List | Where-Object { $_.SkuPartNumber -eq $Name } } } FriendlyName { $FriendlyName | ForEach-Object { $Name = $_ $List | Where-Object { $_.FriendlyName -like $Name } } } SkuId { $SkuId | ForEach-Object { $Name = $_ $List | Where-Object { $_.SkuId -eq $Name } } } All { Return $List } Default {} } } end { if ($UpdateMsftDocs) { try { $Response = Invoke-WebRequest -Uri 'https://learn.microsoft.com/en-us/entra/identity/users/licensing-service-plan-reference' -Method Get -UseBasicParsing -ErrorAction Stop $Response.Content | Select-String -Pattern '<meta name="updated_at" content="([^"]+)"' | ForEach-Object { $UpdatedAt = [datetime]::Parse($_.Matches[0].Groups[1].Value) $ModuleSyncDate = [datetime]'2026-04-07' if ($UpdatedAt -gt $ModuleSyncDate) { Write-Warning "Microsoft Docs were updated on $($UpdatedAt.ToString('yyyy-MM-dd')), which is after the module sync date ($($ModuleSyncDate.ToString('yyyy-MM-dd'))). Consider updating LicNames.csv." } else { Write-Verbose "Microsoft Docs last updated: $($UpdatedAt.ToString('yyyy-MM-dd')). Module is in sync." } } } catch { Write-Warning "Unable to reach Microsoft Docs: $_" } } } } |