Skip to content

Commit

Permalink
Fixing O365 disable and unlicensed users having a size limit causing …
Browse files Browse the repository at this point in the history
…incorrect matches.
  • Loading branch information
chrisjantzen committed Jul 9, 2024
1 parent 3c51f9a commit 8973ebe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 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: Fri Jun 28 2024
# Last Modified: Tue Jul 09 2024
# Modified By: Chris Jantzen
# -----
# Copyright (c) 2023 Sea to Sky Network Solutions
Expand Down Expand Up @@ -2001,8 +2001,9 @@ if ($CheckEmail) {
RecipientTypeDetails, Guid, UserPrincipalName,
DeliverToMailboxAndForward, ForwardingSmtpAddress, ForwardingAddress, HiddenFromAddressListsEnabled |
Where-Object { $_.RecipientTypeDetails -notlike "DiscoveryMailbox" }
$DisabledAccounts = Get-AzureADUser -Filter "AccountEnabled eq false" | Select-Object -ExpandProperty UserPrincipalName
$UnlicensedUsers = Get-AzureADUser | Where-Object {
$AzureUsers = Get-AzureADUser -All $true | Select-Object ObjectID, UserPrincipalName, AccountEnabled, AssignedLicenses, DisplayName, GivenName, Surname, JobTitle
$DisabledAccounts = $AzureUsers | Where-Object { $_.AccountEnabled -eq $false } | Select-Object -ExpandProperty UserPrincipalName
$UnlicensedUsers = $AzureUsers | Where-Object {
$licensed = $false
for ($i = 0; $i -le ($_.AssignedLicenses | Measure-Object).Count ; $i++) {
if ([string]::IsNullOrEmpty($_.AssignedLicenses[$i].SkuId) -ne $true) {
Expand Down Expand Up @@ -2058,7 +2059,6 @@ if ($CheckEmail) {
}

$LicensePlanList = Get-AzureADSubscribedSku
$AzureUsers = Get-AzureADUser -All $true | Select-Object ObjectID, UserPrincipalName, AssignedLicenses, GivenName, Surname, JobTitle
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name AssignedLicenses -Value @()
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name AAD_ObjectID -Value $null
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name PrimaryLicense -Value $null
Expand Down Expand Up @@ -2168,6 +2168,7 @@ if ($CheckEmail) {
$O365MailboxStat = $O365MailboxStats | Where-Object { $_.DisplayName -like $O365Mailboxes[$i].DisplayName }
$O365Mailboxes[$i].LastUserActionTime = $O365MailboxStat.LastLogonTime
}
$UnlicensedUsers = @()
}

if ($EmailType -eq "O365") {
Expand Down
9 changes: 5 additions & 4 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: Fri Jun 28 2024
# Last Modified: Tue Jul 09 2024
# Modified By: Chris Jantzen
# -----
# Copyright (c) 2023 Sea to Sky Network Solutions
Expand Down Expand Up @@ -702,8 +702,9 @@ if ($UserAudit) {
DeliverToMailboxAndForward, ForwardingSmtpAddress, ForwardingAddress, HiddenFromAddressListsEnabled |
Where-Object { $_.RecipientTypeDetails -notlike "DiscoveryMailbox" }
Write-PSFMessage -Level Verbose -Message "Got $(($O365Mailboxes | Measure-Object).Count) mailboxes from O365."
$DisabledAccounts = Get-AzureADUser -Filter "AccountEnabled eq false" | Select-Object -ExpandProperty UserPrincipalName
$UnlicensedUsers = Get-AzureADUser | Where-Object {
$AzureUsers = Get-AzureADUser -All $true | Select-Object ObjectID, UserPrincipalName, AccountEnabled, AssignedLicenses, DisplayName, GivenName, Surname, JobTitle
$DisabledAccounts = $AzureUsers | Where-Object { $_.AccountEnabled -eq $false } | Select-Object -ExpandProperty UserPrincipalName
$UnlicensedUsers = $AzureUsers | Where-Object {
$licensed = $false
for ($i = 0; $i -le ($_.AssignedLicenses | Measure-Object).Count ; $i++) {
if ([string]::IsNullOrEmpty($_.AssignedLicenses[$i].SkuId) -ne $true) {
Expand Down Expand Up @@ -743,7 +744,6 @@ if ($UserAudit) {
}

$LicensePlanList = Get-AzureADSubscribedSku
$AzureUsers = Get-AzureADUser -All $true | Select-Object ObjectID, UserPrincipalName, AssignedLicenses, GivenName, Surname, JobTitle
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name AssignedLicenses -Value @()
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name AAD_ObjectID -Value $null
$O365Mailboxes | Add-Member -MemberType NoteProperty -Name PrimaryLicense -Value $null
Expand Down Expand Up @@ -802,6 +802,7 @@ if ($UserAudit) {
$O365Mailboxes[$i].LastName = $O365MailboxUser.LastName
$O365Mailboxes[$i].Title = $O365MailboxUser.Title
}
$UnlicensedUsers = @()
}

$MailboxCount = ($O365Mailboxes | Measure-Object).Count
Expand Down
2 changes: 1 addition & 1 deletion currentversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.19.5
2.19.6

0 comments on commit 8973ebe

Please sign in to comment.