I have used a script to get all users that have activesync enabled and list all of the connections. Many users have multiple entries where they have used a phone and upgraded, or re-enabled after a wipe.
I am looking to get rid of any entry above 30 days, only for users in a specific OU, or text file full of users.
I believe this code will work universally across the domain:
$DevicesToRemove = Get-ActiveSyncDevice -result unlimited | Get-ActiveSyncDeviceStatistics | where {$_.LastSuccessSync -le (Get-Date).AddDays("-30")}
$DevicesToRemove | foreach-object {Remove-ActiveSyncDevice ([string]$_.Guid) -confirm:$false}
but I only want to do it for either an OU, or txt list.
I can create a .txt list of either the UPN, or the username, which may be easier than looking for all users in an OU. How would I modify that code (or altogether better code?) to remove 30 day+ activesync connections for that txt list?
Text file option would be preferred for a better target.
I think I self answered, so posting for others.
From http://techtalklive.org/ttlblog/removing-stale-activesync-devices/
Then to remove:
From http://techtalklive.org/ttlblog/removing-stale-activesync-devices/