question

DavidAz avatar image
0 Votes"
DavidAz asked joyceshen-MSFT commented

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

 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.

office-exchange-online-itpro
· 4
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.


Would -and make more sense? and use -notmatch perhaps as well.


where {($.DisplayName -notlike 'SDL*' -and $_.managedby -notmatch "Organization Management")}

0 Votes 0 ·

No luck. It's still not working.

0 Votes 0 ·

Did someone add Org mgmt as an owner to all these groups?

So when you use -and , the groups managed by Organization Management still show up?

What if you query just for the groups not managed by "Organization Management"?

0 Votes 0 ·
Show more comments
AndyDavid avatar image
0 Votes"
AndyDavid answered DavidAz commented

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

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

· 3
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.

Not sure why but for me it isn't. I'm running this in ISE with connect-exhangeonline.

0 Votes 0 ·

Hmm, not sure.
But as to why it shows up org mgmt, I believe that any groups syned to 365 without an on-prem owner show up as managed by org Mgmt in Exchange Online

Can you run that same command connecting remotely from the Exo PS Module rather than ISE and see if that makes a difference.

0 Votes 0 ·

Same results.

0 Votes 0 ·
joyceshen-MSFT avatar image
0 Votes"
joyceshen-MSFT answered

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.
 

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.

DavidAz avatar image
0 Votes"
DavidAz answered joyceshen-MSFT commented

This was the solution

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

· 1
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.

Hi,

That's cool! Thanks for sharing the solution!

0 Votes 0 ·