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
Post a Comment