Why is this powershell listing the distribution list when I have a condition to not list it?

DavidAz 21 Reputation points
2021-04-20T14:09:10.953+00:00
Get-DistributionGroup -ResultSize unlimited | where {($_.DisplayName -notlike 'SDL_*') -or  ($_.managedby -notcontains "*Organization Management*")} | ft displayname, managedby

I'm running the above powershell. I've used -notcontains, notequal, notlike and I'm still having distribution lists returned that contain organization management as an owner. What am I missing? I feel like Exchange for some reason added the role Organization management as an owner and that isn't an object the conditions are tracking for.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Andy David - MVP 157.4K Reputation points MVP Volunteer Moderator
    2021-04-20T17:40:56.8+00:00

    Ok, didnt realize this was Exo.
    I just tested this and it worked:

    Get-DistributionGroup -ResultSize unlimited | ?{$_.Managedby -ne 'Organization Management'} 
    

  2. Joyce Shen - MSFT 16,701 Reputation points
    2021-04-21T06:07:44.753+00:00

    Hi @DavidAz

    Do you mean the owner not a member of the default Admin role => Organization Management?

    Please note that the ManagedBy parameter specifies an owner for the group. The owner you specify for this parameter must be a mailbox, mail user or mail-enabled security group (a mail-enabled security principal that can have permissions assigned).

    Also, note that the managedby returns an array. You may need to get the members of the admin role firstly then match the members with them.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
     

    0 comments No comments

  3. DavidAz 21 Reputation points
    2021-04-22T17:26:45.947+00:00

    This was the solution

    [string]@($_.ManagedBy) -notmatch "Organization Management")}


Your answer

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