Solved

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

Posted on 2016-10-06
12
128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 25

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 15

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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

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 15

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
 
LVL 15

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 15

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 15

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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Read this checklist to learn more about the 15 things you should never include in an email signature.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

749 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