locked
ActiveSyncBlockedDeviceIDs not blocking all devices RRS feed

  • Question

  • 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.


    • Moved by Bill_Stewart Wednesday, July 16, 2014 3:30 PM Abandoned
    Thursday, June 5, 2014 6:13 PM

All replies

  • Probably more like this:

    $ids= Get-ActiveSyncDeviceStatistics -Mailbox $User | select -ExpandProperty deviceid | where {$_.deviceid -notlike <string>}


    ¯\_(ツ)_/¯

    Thursday, June 5, 2014 8:51 PM
  • Hi jrv,

    Thanks for the help. Will test it and let you know.

    I tweaked the original script a bit and it's working fine now. Here's the script:

    #Extract Users from OU
    $Users  = Get-ADGroupMember -identity <Group Name> | select -ExpandProperty samaccountname
     
    foreach ( $User in $Users) {
        
        $casMBox = Get-CASMailbox -Identity $User 
            
            foreach ($asdevid in $casMBox.ActiveSyncAllowedDeviceIDs){
                    #Get Activesync Device ID where device ID does not contains a particular string
                        $asdev = get-activesyncdevice -Mailbox $User | where {$_.deviceid -notlike <string>} | select -ExpandProperty deviceid
                    #Block the selected devices
                        Set-CASMailbox -Identity $casMBox.Identity -ActiveSyncBlockedDeviceIDs $asdev
    
                    }
     }

     
    Friday, June 6, 2014 7:32 AM
  • Yes - that will probably accomplish the same thing.


    ¯\_(ツ)_/¯

    Friday, June 6, 2014 10:43 AM