Solved

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

Posted on 2016-10-06
12
39 Views
Last Modified: 2016-10-07
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
0
Comment
Question by:mkllpit
  • 6
  • 5
12 Comments
 
LVL 24

Expert Comment

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

Open in new window

0
 

Author Comment

by:mkllpit
ID: 41832604
Thanks, but it still brings up the mailboxes that are listed in the $test variable.
0
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41832623
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.
0
 

Author Comment

by:mkllpit
ID: 41832626
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.
0
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41832631
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.
0
 

Author Comment

by:mkllpit
ID: 41832643
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.
0
Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

 
LVL 14

Accepted Solution

by:
Todd Nelson earned 500 total points
ID: 41832647
If you want it to be unobtrusive, export your list of mailboxes to a CSV, remove those mailboxes from the CSV you don't want affected, and then run the command to set the value you want using the CSV.

Export mailbox names to CSV...

Get-Mailbox | Select-Object name | Export-Csv "C:\Mailboxes.csv" -NoTypeInformation

Open in new window


Remove names from list that exist in specific DL

Then disable OA for specific list of users...

Import-Csv "C:\Mailboxes.csv" | ForEach-Object { Set-CASMailbox -Identity $_.Name -MAPIBlockOutlookRpcHttp $false }

Open in new window


You now have 2 viable options.

Let me know.
0
 

Author Comment

by:mkllpit
ID: 41832652
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
0
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41832655
Good luck.  Again, I'm interested in what you come up with or decide.
0
 

Author Comment

by:mkllpit
ID: 41833813
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.
0
 

Author Closing Comment

by:mkllpit
ID: 41833814
great help
0
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41833828
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.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now