Disable activesync for all users, with exception list

Posted: February 10, 2011 in Exchange, Scripts

The following powershell script reads in a list of names from a CSV file, which has just one column with header “Name”. It disables active sync for all users and then goes back and renables for the list of users in the CSV.

$ASUsers = Import-CSV c:\scripts\ASUsers.csv

Get-Mailbox | Set-CASMailbox -ActiveSyncEnabled:$False

foreach ($name in $ASUsers){
 $username = $name.Name
 get-mailbox -ResultSize Unlimited | where{$_.name -eq “$username”}| Set-CASMailbox -ActiveSyncEnabled:$True
}

It’s a bit slow. The better option would be to use get-mailbox -filter, but I couldn’t get the variable passed to it correctly, so this had to do.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s