question

marioo1215 avatar image
0 Votes"
marioo1215 asked ElevenYu-MSFT edited

list mailboxes from aad group

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"}
}

azure-active-directorywindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

NewbieJones-6218 avatar image
0 Votes"
NewbieJones-6218 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.