Hi,
I am trying to write a script that will block all ActiveSync devices except those whose Device ID contains a particular string.
The script is as below:
#Extract Users from OU
$Users = <username>
Foreach ( $User in $Users) {
#Get Activesync Device List for a user and select devices with device ID not containing a particular string
$DeviceIDs = Get-ActiveSyncDeviceStatistics -Mailbox $User | where {$_.deviceid -notlike <string>} | select -ExpandProperty deviceid
Foreach ($DeviceID in $DeviceIDs){
#Block all the selected devices
Set-CASMailbox -Identity $User -ActiveSyncBlockedDeviceIDs $DeviceID
}
}
Most of it is working fine except in the scenario where multiple devices of the same user are to be blocked. In this case it just block the last device ID it executes.