@@ -20,27 +20,29 @@ Function Invoke-ListSharedMailboxAccountEnabled {
2020 # Get Shared Mailbox Stuff
2121 try {
2222 $SharedMailboxList = (New-GraphGetRequest - uri " https://outlook.office365.com/adminapi/beta/$ ( $TenantFilter ) /Mailbox?`$ filter=RecipientTypeDetails eq 'SharedMailbox'" - Tenantid $TenantFilter - scope ExchangeOnline)
23- $AllUsersAccountState = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/users?select=id,userPrincipalName,accountEnabled,displayName,givenName,surname,onPremisesSyncEnabled' - tenantid $TenantFilter
24- $EnabledUsersWithSharedMailbox = foreach ($SharedMailbox in $SharedMailboxList ) {
23+ $AllUsersInfo = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/users?$ select=id,userPrincipalName,accountEnabled,displayName,givenName,surname,onPremisesSyncEnabled,assignedLicenses ' - tenantid $TenantFilter
24+ $SharedMailboxDetails = foreach ($SharedMailbox in $SharedMailboxList ) {
2525 # Match the User
26- $User = $AllUsersAccountState | Where-Object { $_.userPrincipalName -eq $SharedMailbox.userPrincipalName } | Select-Object - Property id, userPrincipalName, accountEnabled, displayName, givenName, surname, onPremisesSyncEnabled - First 1
27- if ($User.accountEnabled ) {
28- $User | Select-Object `
29- @ {Name = ' UserPrincipalName' ; Expression = { $User.UserPrincipalName } }, `
30- @ {Name = ' displayName' ; Expression = { $User.displayName } },
31- @ {Name = ' givenName' ; Expression = { $User.givenName } },
32- @ {Name = ' surname' ; Expression = { $User.surname } },
33- @ {Name = ' accountEnabled' ; Expression = { $User.accountEnabled } },
34- @ {Name = ' id' ; Expression = { $User.id } },
35- @ {Name = ' onPremisesSyncEnabled' ; Expression = { $User.onPremisesSyncEnabled } }
36-
26+ $User = $AllUsersInfo | Where-Object { $_.userPrincipalName -eq $SharedMailbox.userPrincipalName } | Select-Object - First 1
27+
28+ if ($User ) {
29+ # Return all shared mailboxes with license information
30+ [PSCustomObject ]@ {
31+ UserPrincipalName = $User.userPrincipalName
32+ displayName = $User.displayName
33+ givenName = $User.givenName
34+ surname = $User.surname
35+ accountEnabled = $User.accountEnabled
36+ assignedLicenses = $User.assignedLicenses
37+ id = $User.id
38+ onPremisesSyncEnabled = $User.onPremisesSyncEnabled
39+ }
3740 }
3841 }
3942 } catch {
40- Write-LogMessage - API ' Tenant' - tenant $TenantFilter - message " Shared Mailbox Enabled Accounts on $ ( $TenantFilter ) . Error: $ ( $_.exception.message ) " - sev ' Error'
43+ Write-LogMessage - API ' Tenant' - tenant $TenantFilter - message " Shared Mailbox List on $ ( $TenantFilter ) . Error: $ ( $_.exception.message ) " - sev ' Error'
4144 }
42-
43- $GraphRequest = $EnabledUsersWithSharedMailbox
45+ $GraphRequest = $SharedMailboxDetails
4446 # Associate values to output bindings by calling 'Push-OutputBinding'.
4547 Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
4648 StatusCode = [HttpStatusCode ]::OK
0 commit comments