Skip to content

Commit

Permalink
Fixing broken O365 assigned licenses from last update.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjantzen committed Jun 6, 2024
1 parent ee10a6f commit 4ab9c11
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
36 changes: 28 additions & 8 deletions User Audit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Created Date: Tuesday, August 2nd 2022, 10:36:05 am
# Author: Chris Jantzen
# -----
# Last Modified: Tue Jun 04 2024
# Last Modified: Thu Jun 06 2024
# Modified By: Chris Jantzen
# -----
# Copyright (c) 2023 Sea to Sky Network Solutions
Expand Down Expand Up @@ -2042,6 +2042,21 @@ if ($CheckEmail) {
}
}

if (!$LicenseTranslationTable) {
New-Item -ItemType Directory -Force -Path "C:\Temp" | Out-Null
Invoke-WebRequest -Uri "https://download.microsoft.com/download/e/3/e/e3e9faf2-f28b-490a-9ada-c6089a1fc5b0/Product%20names%20and%20service%20plan%20identifiers%20for%20licensing.csv" -OutFile "C:\Temp\O365LicenseTranslationTable.csv"
$FullLicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
$LicenseTranslationTable_Temp = $FullLicenseTranslationTable |
Group-Object String_Id, Product_Display_Name |
Foreach-Object { $_.Group | Select-Object String_Id, Product_Display_Name -First 1} |
Sort-Object String_Id, Product_Display_Name

$LicenseTranslationTable = @{}
$LicenseTranslationTable_Temp | ForEach-Object {
$LicenseTranslationTable[$_.String_Id] = $_.Product_Display_Name
}
}

$LicensePlanList = Get-AzureADSubscribedSku
$AzureUsers = Get-AzureADUser -All $true | Select-Object ObjectID, UserPrincipalName, AssignedLicenses, GivenName, Surname, JobTitle
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name AssignedLicenses -Value @()
Expand Down Expand Up @@ -2099,15 +2114,19 @@ if ($CheckEmail) {
$Licenses = @()
$LicenseSkus | ForEach-Object {
$sku = $_.SkuId
$PrettyName = ($LicenseTranslationTable | Where-Object {$_.GUID -eq $sku } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
$Licenses += $PrettyName
foreach ($license in $licensePlanList) {
if ($sku -eq $license.ObjectId.substring($license.ObjectId.length - 36, 36)) {
$Licenses += $license.SkuPartNumber
break
}
}
}
$_.AssignedLicenses = $Licenses
$_.PrimaryLicense = "None"

foreach ($PrimaryLicenseType in $O365LicenseTypes_Primary.GetEnumerator()) {
if ($PrimaryLicenseType.Value -in $Licenses) {
$_.PrimaryLicense = $PrimaryLicenseType.Value
if ($PrimaryLicenseType.Key -in $Licenses) {
$_.PrimaryLicense = $LicenseTranslationTable[$PrimaryLicenseType.Key]
break
}
}
Expand Down Expand Up @@ -3489,6 +3508,7 @@ if ($EmailType -eq "O365") {
foreach ($License in $LicensePlanList) {
if ($License.ConsumedUnits -lt $License.PrepaidUnits.Enabled -and $License.SkuPartNumber -notlike "*FREE*") {
$UnusedLicenses += [pscustomobject]@{
$PrettyName = ($LicenseTranslationTable | Where-Object {$_.GUID -eq $License.SkuPartNumber } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
License = $O365LicenseTypes[$License.SkuPartNumber]
Amount = ($License.PrepaidUnits.Enabled - $License.ConsumedUnits)
}
Expand All @@ -3510,7 +3530,7 @@ if ($EmailType -eq "O365") {
$AllowedLicenses = ($O365StandardLicenses | Where-Object { $_.Types -like $Match.Type }).Licenses
foreach ($AssignedLicense in $O365Mailbox.AssignedLicenses) {
# only check primary licenses
if ($AssignedLicense -in $O365LicenseTypes_Primary.keys -and $AllowedLicenses) {
if ($AssignedLicense -in $O365LicenseTypes_Primary.values -and $AllowedLicenses) {
if ($AssignedLicense -notin $AllowedLicenses -or $AllowedLicenses -contains "None") {
$BadLicenses += [pscustomobject]@{
"O365 Name" = $Match."O365-Name"
Expand Down Expand Up @@ -4241,7 +4261,7 @@ if ($ExportChoice -eq 'Yes') {
if (!$LicenseTranslationTable) {
New-Item -ItemType Directory -Force -Path "C:\Temp" | Out-Null
Invoke-WebRequest -Uri "https://download.microsoft.com/download/e/3/e/e3e9faf2-f28b-490a-9ada-c6089a1fc5b0/Product%20names%20and%20service%20plan%20identifiers%20for%20licensing.csv" -OutFile "C:\Temp\O365LicenseTranslationTable.csv"
$LicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
$FullLicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
}

$LicenseList = @()
Expand All @@ -4250,7 +4270,7 @@ if ($ExportChoice -eq 'Yes') {
$Licenses = @()
$LicenseSkus | ForEach-Object {
$sku = $_.SkuId
$PrettyName = ($LicenseTranslationTable | Where-Object {$_.GUID -eq $sku } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
$PrettyName = ($FullLicenseTranslationTable | Where-Object {$_.GUID -eq $sku } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
$Licenses += $PrettyName
}

Expand Down
32 changes: 23 additions & 9 deletions User_Billing_Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Created Date: Tuesday, August 2nd 2022, 10:36:05 am
# Author: Chris Jantzen
# -----
# Last Modified: Tue Jun 04 2024
# Last Modified: Thu Jun 06 2024
# Modified By: Chris Jantzen
# -----
# Copyright (c) 2023 Sea to Sky Network Solutions
Expand Down Expand Up @@ -730,7 +730,16 @@ if ($UserAudit) {
if (!$LicenseTranslationTable) {
New-Item -ItemType Directory -Force -Path "C:\Temp" | Out-Null
Invoke-WebRequest -Uri "https://download.microsoft.com/download/e/3/e/e3e9faf2-f28b-490a-9ada-c6089a1fc5b0/Product%20names%20and%20service%20plan%20identifiers%20for%20licensing.csv" -OutFile "C:\Temp\O365LicenseTranslationTable.csv"
$LicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
$FullLicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
$LicenseTranslationTable_Temp = $FullLicenseTranslationTable |
Group-Object String_Id, Product_Display_Name |
Foreach-Object { $_.Group | Select-Object String_Id, Product_Display_Name -First 1} |
Sort-Object String_Id, Product_Display_Name

$LicenseTranslationTable = @{}
$LicenseTranslationTable_Temp | ForEach-Object {
$LicenseTranslationTable[$_.String_Id] = $_.Product_Display_Name
}
}

$LicensePlanList = Get-AzureADSubscribedSku
Expand All @@ -749,15 +758,19 @@ if ($UserAudit) {
$Licenses = @()
$LicenseSkus | ForEach-Object {
$sku = $_.SkuId
$PrettyName = ($LicenseTranslationTable | Where-Object {$_.GUID -eq $sku } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
$Licenses += $PrettyName
foreach ($license in $licensePlanList) {
if ($sku -eq $license.ObjectId.substring($license.ObjectId.length - 36, 36)) {
$Licenses += $license.SkuPartNumber
break
}
}
}
$_.AssignedLicenses = $Licenses
$_.PrimaryLicense = "None"

foreach ($PrimaryLicenseType in $O365LicenseTypes_Primary.GetEnumerator()) {
if ($PrimaryLicenseType.Value -in $Licenses) {
$_.PrimaryLicense = $PrimaryLicenseType.Value
if ($PrimaryLicenseType.Key -in $Licenses) {
$_.PrimaryLicense = $LicenseTranslationTable[$PrimaryLicenseType.Key]
break
}
}
Expand Down Expand Up @@ -2701,10 +2714,11 @@ if ($CheckEmail -and $EmailType -eq "O365") {
Write-PSFMessage -Level Verbose -Message "Exporting Office 365 License Report."
$LicensePlanList = Get-AzureADSubscribedSku
$AzureUsers = Get-AzureADUser -All $true | Select-Object UserPrincipalName, AssignedLicenses, DisplayName, GivenName, Surname

if (!$LicenseTranslationTable) {
New-Item -ItemType Directory -Force -Path "C:\Temp" | Out-Null
Invoke-WebRequest -Uri "https://download.microsoft.com/download/e/3/e/e3e9faf2-f28b-490a-9ada-c6089a1fc5b0/Product%20names%20and%20service%20plan%20identifiers%20for%20licensing.csv" -OutFile "C:\Temp\O365LicenseTranslationTable.csv"
$LicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
$FullLicenseTranslationTable = Import-CSV -Path "C:\Temp\O365LicenseTranslationTable.csv"
}

$LicenseList = @()
Expand All @@ -2713,7 +2727,7 @@ if ($CheckEmail -and $EmailType -eq "O365") {
$Licenses = @()
$LicenseSkus | ForEach-Object {
$sku = $_.SkuId
$PrettyName = ($LicenseTranslationTable | Where-Object {$_.GUID -eq $sku } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
$PrettyName = ($FullLicenseTranslationTable | Where-Object {$_.GUID -eq $sku } | Sort-Object Product_Display_Name -Unique).Product_Display_Name
$Licenses += $PrettyName
}

Expand All @@ -2726,7 +2740,7 @@ if ($CheckEmail -and $EmailType -eq "O365") {

foreach ($PrimaryLicenseType in $O365LicenseTypes_Primary.GetEnumerator()) {
if ($PrimaryLicenseType.Value -in $Licenses) {
$UserInfo.PrimaryLicense = $PrimaryLicenseType.Value
$_.PrimaryLicense = $PrimaryLicenseType.Value
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion currentversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.19.1
2.19.2

0 comments on commit 4ab9c11

Please sign in to comment.