list mailboxes from aad group

Mario Grdiša 86 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 for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Newbie Jones 1,401 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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.