We help IT Professionals succeed at work.

Search mailbox content of Distribution Group members only

Anthony K O365
I need to do a search of mailbox content of members of two distribution groups, not the entire Exchange organization, Please assist with PS script
Comment
Watch Question

Anthony K O365Messaging Consulting

Author

Commented:
This is an Exchange 2016 organization On Prem
Messaging Consulting
I was able to use the following command to search only in the mailboxes of those in this  DG.  However, I still the confirmation prompt. Not sure why...

$Users = Get-DistributionGroupMember -Identity "GroupA"

foreach ($User in $Users) {
  Get-Mailbox -Identity $User.name |  Search-Mailbox -SearchQuery attachment: filename –TargetMailbox administrator -TargetFolder “Folder name” –LogOnly -LogLevel Full -confirm:$false

}
Anthony K O365Messaging Consulting

Author

Commented:
Correction:

I was able to use the following command to search only in the mailboxes of those in this  DG.  However, I still get the confirmation prompt. Not sure why...

$Users = Get-DistributionGroupMember -Identity "GroupA"

foreach ($User in $Users) {
  Get-Mailbox -Identity $User.name |  Search-Mailbox -SearchQuery attachment: filename –TargetMailbox administrator -TargetFolder “Folder name” –DeleteContent  -LogLevel Full -confirm:$false

}
Anthony K O365Messaging Consulting

Author

Commented:
I needed to use the -Force switch which overrides the confirmation switch.