Solved

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

Posted on 2016-10-06
12
72 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 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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intune/ Microsoft EMS 1 36
Powershell script to remove white space 3 29
exchange, email gateway 2 31
Powershell Script Help, Office 365 Exchange migration 9 34
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
In this video we show how to create a Distribution Group 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 >>…
In this video we show how to create a Shared Mailbox 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 >> Sha…

778 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