Exchange Management Shell command with exception
I am a Powershell / Exchange shell amateur to be sure. What I would like to do is run a command against all mailboxes except if they are a member of a specific distribution group. How would I build that exception in the command? Or am I moving past a single command and on to an actual script? Basically I would like to disable Active-Sync (either globally or at the server level) except if they are a member of a specific distribution group. Thanks
February 17th, 2010 9:45pm

Try:get-mailbox |? {(get-distributiongroupmember <distribution group>) -notcontains $_}
Free Windows Admin Tool Kit Click here and download it now
February 17th, 2010 10:06pm

Thank you very much, that doesn't seem to sort out the mailboxes that are members of the List. I just get a list of all the mailboxes. Any other ideas?
February 17th, 2010 10:35pm

I'll get back to you in a bit.
Free Windows Admin Tool Kit Click here and download it now
February 17th, 2010 11:01pm

Here's another idea.. $exclude = Get-DistributionGroupMember <distribution group> | %{$_.name} get-mailbox | ?{$exclude -notcontains $_.name}
February 17th, 2010 11:25pm

That works. Doesn't seem like it ought to be that hard, tho.
Free Windows Admin Tool Kit Click here and download it now
February 17th, 2010 11:36pm

Thanks yes that does, indeed, work. I was really hoping that it could be a one-liner but I can certainly make that work! Thank you!
February 17th, 2010 11:45pm

That works. Doesn't seem like it ought to be that hard, tho. agreed.
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2010 12:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics