Powershell Setting Active Sync Based on group membership


#Start-Transcript c:\activesyncerror.txt


# Set Report File
echo MM > "c:\active.csv"
$outfile = "c:\active.csv"

#Users to query
$user = Get-CASMailbox -resultsize unlimited
foreach ($userfound in $user)
{
$userdn = $userfound.distinguishedName
$usersm = $userfound.SamAccountName
$ADuser=[ADSI]"LDAP://$userdn"
$res = $aduser.memberOf
#$res

#Group to query membership off
$group = get-group "pda users"
$groupdn = $group.distinguishedName
$ADGroup=[ADSI]"LDAP://$Groupdn"

#Check if user is a member of the group
#if not then Active Sync is disabled for the account




if ($res -contains $ADGroup.distinguishedName)

{Write-output "$usersm Is a member of  $group , Enabled" >> $outfile
#Set-CASMailbox $users.SamAccountName -ActiveSyncEnabled $true
Write-Host $usersm "Enabled"
}

if ($res -notcontains $ADGroup.distinguishedName)

{Write-output "$usersm Is not a member of  $group , Disabled" >> $outfile
Set-CASMailbox $usersm â€"ActiveSyncEnabled $false -whatif
Write-host $usersm "Disabled"
}
}
#Stop-Transcript
$users.count
notepad $outfile

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.