locked
Find DL's with a group member and missing group members. RRS feed

  • Question

  • Hello ,
    someone can please guide me how to add - and -notcontains to this?


    Get-DistributionGroup -ResultSize Unlimited -erroraction 'silentlycontinue' | where { (Get-DistributionGroupMember $_.Name -erroraction 'silentlycontinue'| foreach {$_.PrimarySmtpAddress}) -contains "$Gmember" -and -notcontains "$GmemberNot" }

    basically i want to find DL's with a group member and without specific group member

    thank you



    • Edited by RWiez Thursday, February 14, 2019 6:27 PM
    Thursday, February 14, 2019 6:16 PM

All replies

  • The correct method for this is as follows:

    $_.PrimarySmtpAddress -contains $Gmember -and $_.PrimarySmtpAddress -notcontains $GmemberNot 


    \_(ツ)_/

    Thursday, February 14, 2019 7:17 PM
  • thank you , changing to this:

    Get-DistributionGroup -ResultSize Unlimited -erroraction 'silentlycontinue' | where { (Get-DistributionGroupMember $_.Name -erroraction 'silentlycontinue'| foreach {$_.PrimarySmtpAddress }) -contains $Gmember -and $_.PrimarySmtpAddress -notcontains $GmemberNot }

    Output for groups with $Gmember but also for group with the $GmemberNot which not what i expected.

    Friday, February 15, 2019 8:58 AM
  • It would help if you learned PowerShell first.

    Get-DistributionGroup -ResultSize Unlimited  | 
        ForEach-Object{ Get-DistributionGroupMember $_.Name } |
        Where-Object { $_.PrimarySmtpAddress -in $Gmember -and $_.PrimarySmtpAddress -notin $GmemberNot }

    What you are trying to do is very vague.


    \_(ツ)_/


    • Edited by jrv Friday, February 15, 2019 9:14 AM
    Friday, February 15, 2019 9:08 AM
  • The correct method for this is as follows:

    $_.PrimarySmtpAddress -contains $Gmember -and $_.PrimarySmtpAddress -notcontains $GmemberNot 


    \_(ツ)_/

    This should be:

    $_.PrimarySmtpAddress -in $Gmember -and $_.PrimarySmtpAddress -notin $GmemberNot

    $gmember and $gmembernot must be arrays of addresses.


    \_(ツ)_/


    • Edited by jrv Friday, February 15, 2019 9:16 AM
    Friday, February 15, 2019 9:15 AM
  • that's just output $gmember multiple times
    and get the following error during the run:


    The operation couldn't be performed because '***********' matches multiple entries.
    Friday, February 15, 2019 12:21 PM
  • You must post the actual and complete error message.

    You also have to be clear  about what you are referring to.  Don't make us guess what you are posting about.


    \_(ツ)_/

    Friday, February 15, 2019 12:23 PM
  • Sorry, see the full error that shows during the scan on some of the groups 

    *************.com MailContact
    *************.com MailContact
    *************.com MailContact
    *************.com MailContact
    *************.com MailContact
    The operation couldn't be performed because '******HIDDEN(Group NAME)******' matches multiple entries.
        + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : [Server=*****Hidden******,RequestId=ab801eb8-b6e6-487d-ba1e-03f251bac77e,TimeStamp=2/15/2019
        9:50:33 AM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 18F0145B,Microsoft.Exchange.Management.Rec
      ipientTasks.GetDistributionGroupMember
        + PSComputerName        : ps.outlook.com

    I just want have all distribution lists with a selected member that have to be also without another selected member.

    • Edited by RWiez Friday, February 15, 2019 1:19 PM
    Friday, February 15, 2019 1:15 PM
  • Still not the complete error and we have no idea what code you are running.


    \_(ツ)_/

    Friday, February 15, 2019 1:23 PM
  • Here it is:

    $Gmember = read-host "Enter a group member "

    $GmemberNot = read-host "Enter a group member that should not be in the DL's result "

    Get-DistributionGroup -ResultSize Unlimited  | 
        ForEach-Object{ Get-DistributionGroupMember $_.Name } |
        Where-Object { $_.PrimarySmtpAddress -in $Gmember -and $_.PrimarySmtpAddress -notin $GmemberNot }

    Friday, February 15, 2019 2:35 PM
  • Go use a string you would use "-eq" to compare with a string.


    \_(ツ)_/


    • Edited by jrv Friday, February 15, 2019 6:09 PM
    Friday, February 15, 2019 6:09 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, February 28, 2019 9:56 AM