Code Dump: Remove Active Sync Devices Older than 90 Days

Get-CASMailbox -ResultSize unlimited -Filter{(HasActiveSyncDevicePartnership -eq $true) -AND (name -notlike “cas_*”) -AND (name -notlike “DiscoverysearchMailbox*”)} | ForEach {Get-mobileDeviceStatistics -Mailbox:$_.Identity | Where-Object {$_.LastSuccessSync -le (Get-Date).AddDays(“-90”)}} | Remove-MobileDevice

Read More

Code Dump: Change UPN for all members of an AD Group

$ADGROUP=”TEST” $OLDUPN=”@OLDDOMAIN.COM” $NEWUPN=”@NEWDOMAIN.COM” $GRPMEM=Get-ADGroupMember $ADGROUP Get-ADGroupmember $ADGROUP | ForEach-Object { $USER=Get-ADUser $_.samaccountname $UPN = $USER.UserPrincipalName.Replace($OLDUPN,$NEWUPN) Set-ADUser $USER.samaccountname -UserPrincipalName $UPN }

Read More