Help with Exchange PowerShell script to disable ActiveSync for all users


i error when running script disable activesync users in org. 

sending data remote command failed following error message: total data received remote client exceeded allowed maximum. allowed maximum 524288000. more information, see about_remote_troubleshooting topic.

can me modify script run more effifiently?

 

$ad = (get-group ‘security group').members | select objectguid | foreach-object {get-user -identity ([string]$_.objectguid)} | select name,distinguishedname

$ex = get-mailboxdatabase | get-mailbox -resultsize unlimited | get-casmailbox -resultsize unlimited | {$_.activesyncenabled} | select name,distinguishedname

$ex | foreach-object {if (($ad | foreach-object {$_.distinguishedname}) -notcontains $_.distinguishedname) {set-casmailbox -identity $_.distinguishedname -activesyncenabled $false}}

$ad | foreach-object {if (($ex | foreach-object {$_.distinguishedname}) -notcontains $_.distinguishedname) {set-casmailbox -identity $_.distinguishedname -activesyncenabled $true}}

try script below:

function check-groupmember{

param($user,$grp)

$strfilter = "(&(objectclass=group)(name=" + $grp +"))"

$objdomain = new-object system.directoryservices.directoryentry

$objsearcher = new-object system.directoryservices.directorysearcher
$objsearcher.searchroot = $objdomain
$objsearcher.pagesize = 1000
$objsearcher.filter = $strfilter
$objsearcher.searchscope = "subtree"

$colresults = $objsearcher.findone()

$objitem = $colresults.properties
([string]$objitem.member).contains($user)

}

get-mailbox |foreach{if(!(check-groupmember $_.name "security group")){set-casmailbox -identity $_.name -activesyncenabled $false}}



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS