Disable ActiveSync for Mailbox Users using Powershell

We can enable and disable Exchange ActiveSync feature for mailbox users using Set-CASMailbox cmdlet. In this article, I am going write Powershell scirpt to disable ActiveSync feature for a single user and disable ActiveSync feature for a set of users.

Before proceed, run the following command to enable Exchange cmdlets if you are working with Powershell console instead of Exchange Management Shell.

Add-PSSnapin *Exchange*

Disable Exchange ActiveSync for a Single User

Run the following command to disable Exchange ActiveSync for a single user:

Set-CASMailbox -Identity "Morgan" -ActiveSyncEnabled $False

Run the below command and check the ActiveSync feature is disabled or not for the corresponding user which you have used in the above command.

Get-CASMailbox -ResultSize Unlimited

Disable ActiveSync Feature for a Group of Users

We can use the Active Directory powershell cmdlet Get-ADUser to get a group of users and pass the selected users to Set-CASMailbox cmdlet to disable ActiveSync feature. We can set target OU and apply filter in Get-ADUser cmdlet to get specific set of users. Before proceed, run the following command to import Active Directory powershell cmdlets.

Import-Module ActiveDirectory

The following powershell command select and disable ActiveSync feature for all the users from the container TestOU.

$users = Get-ADUser -Filter * -SearchBase "OU=TestOU,DC=TestDomain,DC=com";
$users | ForEach-Object {
Set-CASMailbox -Identity $_.Name -ActiveSyncEnabled $False
}

The following command select and disable Exchange ActiveSync feature for all the users who are under Testing department.

$users = Get-ADUser -Filter 'Department -like "*Testing*"';
$users | ForEach-Object {
Set-CASMailbox -Identity $_.Name -ActiveSyncEnabled $False
}

Disable ActiveSync Feature for Multiple Users

Use the below powershell script to disable Exchange ActiveSync connectivity for a set of mailbox users. Give the set of user names as string Array.

$users = "usr1","usr2","usr3","usr4"
Foreach($user in $users) {
Set-CASMailbox -Identity $user -ActiveSyncEnabled $False
}
Advertisement

Leave a Comment