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

Tech Quip: Primary ProxyAddress

In an Azure AD Sync, the ProxyAddress with SMTP is treated as the primary email address. All others should be prefaced with “smtp” in lowercase. If there are more than one in all caps, it takes the first alphabetically. Get-ADUser -Filter * -Properties SamAccountName, ProxyAddresses | ft samaccountname,proxyaddresses Set-ADUser -Identity NAME -Clear ProxyAddresses Set-ADUser -Identity […]

Read More

Code Dump: Format Autopsy Results

#!/bin/bash DATE=”” cat timeline.txt | while read line; do if [[ $(echo $line | egrep “[A-Z][a-z]+ [A-Z][a-z]+ [0-9]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+” | wc -l) -gt 0 ]] then DATE=$(echo $line| sed “s/\([A-Z][a-z]* [A-Z][a-z]* [0-9]* [0-9]* [0-9]*:[0-9]*:[0-9]*\).*/\1/” ) echo $line >> timelinefixed.txt echo $line else echo “$DATE $line” >> timelinefixed.txt echo “$DATE $line” fi done

Read More