Link to home
Start Free TrialLog in
Avatar of mkllpit
mkllpitFlag for United States of America

asked on

Exchange Powershell Script - Need to get CasMailbox for all users excluding those in a specific DL

I need to Get, then ultimately Set the MapiBlockOutlookRpcHttp for All users except for those in a specific Distribution List.

I've tried many different variations and they all start of with creating a String variable to get the members of that DL:

$test=Get-DistributionGroupMember "Group A"

The last script I attempted was:

Get-ADUser -SearchBase "ou=accounts,dc=domain,dc=com" -filter {Name -notlike $test } | select name

and

Get-casmailbox -OrganizationalUnit "OU=accounts,dc=domain,dc=com" | where{$_.Name -ne $test}

I've tried every variation with and without single/double quotes. It does work if I input a specific user Name, but not with the String Variable.

Any help would be greatly appreciated.

Thanks
Avatar of M A
M A
Flag of United States of America image

Hi,
Please try this
Get-mailbox -OrganizationalUnit "ou=accounts,dc=domain,dc=com" | where {$_.name -ne "test"}

Open in new window

Avatar of mkllpit

ASKER

Thanks, but it still brings up the mailboxes that are listed in the $test variable.
Wouldn't it be easier to block OA for all mailboxes (set the MAPIBlockOutlookRpcHttp value to $true) and then disable OA for those in the specific DL (set the MAPIBlockOutlookRpcHttp value to $false)?

Like this...

Disable OA for all mailboxes...

Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -MAPIBlockOutlookRpcHttp $true

Open in new window


Then, enable OA for mailboxes in a specific DL...

Get-DistributionGroupMember -Identity "DISTRIBUTION_GROUP_NAME" | ForEach-Object { Set-CASMailbox -Identity $_.Name -MAPIBlockOutlookRpcHttp $false }

Open in new window


Let me know.
Avatar of mkllpit

ASKER

Thanks, I've thought of that and agree it would probably work. This has now become a grudge against Exchange, I want to figure out how to do this.
It does work.  I just ran it in my test environment.

Don't spin your wheels for too long.  But I would be interested to see what combination of commands that you come up with if you accomplish it.
Avatar of mkllpit

ASKER

Thanks for testing. Ideally I would like to have a command to be 100% unobtrusive to the end-users, rather than disable then re-enable. I'll see what I can come up with and post it.
ASKER CERTIFIED SOLUTION
Avatar of Todd Nelson
Todd Nelson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mkllpit

ASKER

Ah, great solution. I'm gonna hold that as my backup if I can't figure the alternative out before the end of today.
Thanks
Good luck.  Again, I'm interested in what you come up with or decide.
Avatar of mkllpit

ASKER

I'm going with your first suggestion, thanks again. Just an FYI, need to remove the foreach-object, this is because it's already piping and the foreach command essentially pipes again.

Whatever that means, ha!

Really appreciate the assistance.
Avatar of mkllpit

ASKER

great help
Sorry about that command.  Good catch.  Don't really know why I added the "foreach".  It should be this instead...

Get-DistributionGroupMember -Identity "DISTRIBUTION_GROUP_NAME" | Set-CASMailbox -Identity $_.Name -MAPIBlockOutlookRpcHttp $false

Open in new window


Glad it worked out for you.