Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-06
12
Medium Priority
?
285 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 27

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 16

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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 

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 16

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 16

Accepted Solution

by:
Todd Nelson earned 2000 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 16

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 16

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

661 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