Powershell get mailbox not member of distribution group RRS feed

  • Question

  • Hello all

    I am trying to use powershell to show me all the mailboxes that are not a members of certain groups. Below code is what I have tried so far, but my results do not seem accurate. Basically I need a list of all mailboxes that are not a member of any groups that contain the contain the name "Archive"

    Thank you for any suggestions on this

     Get-Mailbox -ResultSize unlimited -OrganizationalUnit "OU=Offices,DC=mydomain,DC=lan" |? {$_.distributiongroupmember -notlike "archive*"}

    Bulls on Parade

    Wednesday, September 2, 2015 11:37 PM

All replies

  • Hey, not sure if you still need this... but this was an interesting one...spent all day on it and think I have what you need.

    Try this.

    $MB = Get-Mailbox
    $DG = Read-Host -Prompt 'Distribution Group'
    ForEach ($MB in $MB) {
    $DGM = Get-DistributionGroupMember $DG
    IF ($MB.Name -notin $DGM.Name){
    Write-host $MB.Name

    • Proposed as answer by Damean Berry Wednesday, December 9, 2015 12:20 PM
    • Edited by Damean Berry Wednesday, December 9, 2015 12:21 PM
    Monday, November 9, 2015 11:42 PM
  • Hi ,

    You can use the custom attributes fields for mark and then use it to deny users you don't want to apply command on ,

    Example :

    Get-DistributionGroupMember "DG" | Set-Mailbox -CustomAttribute10 'Execluded'

    get-mailbox |where {$_.CustomAttribute10 -ne 'excluded'}

    it will retrieve users not in the wanted distribution group .

    Wednesday, December 2, 2015 8:47 AM