list mailboxes from aad group

Mario Grdiša 81 Reputation points
2022-05-06T11:25:50.453+00:00

Hi,

i'm tring list mailboxes without archive from specific AAD group.
bellow is a code.
Variable $Users returns all members of a group, but variable $SearchResult return just one user from AD Group.

can somebody tell me what i'm doing wrong?

$Users = Get-AzureADGroupMember -ObjectId "d11221a1-f71d-4f37-0641-aff66fb95917"
foreach ($User in $Users) {
$SearchResult = Get-Mailbox $User.userprincipalname -Filter {ArchiveStatus -Eq "None" -AND RecipientTypeDetails -eq "UserMailbox"}
}

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,460 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,596 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Newbie Jones 1,331 Reputation points
    2022-05-06T12:04:26.527+00:00

    Basically, the $SearchResults are getting overwritten on each loop, so you probably only have the results of the last account in the group.

    Remove the $SearchResults and just pipe the results of the foreach loop into a Select-Object or Export-CSV.

    Remove the filter to start with, and use Select-Object to display the ArchiveStatus and RecipientTypeDetails and have a look at the results on screen.

    I've not seen that before, where you know the identity of the mailbox, and then use a filter.
    Perhaps remove the filter from the Get-Mailbox command, and pipe the results of the Get-Mailbox command into Where-Object and filter client side on ArchiveStatus and ReceipientTypeDetails instead.

    0 comments No comments