locked
Exchange 2010 Powershell script to display all activesync devices/users RRS feed

  • Question

  • Found the script in another thread around here.

    This is exactly what i'm trying to accomplish, a list with all the Activesync users, and devices, however, running the below script when the user have more than one device, just bring all the devices for that user, but it duplicates the first device information.

    $racfs = Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"}

    #array to store final results
    $stats = @()

    $racfs | Foreach {
    #select the properties you want from both objects (activesync props will be empty)
    $m = $_ | select DisplayName, name, DeviceFriendlyName, Devicetype, DeviceUserAgent, FirstSyncTime, LastSuccessSync

    #get the activesync stats
    foreach ($Device in Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity)
    {

    #populate empty active sync properties on your previous object
    $m.DeviceFriendlyName = $Device.DeviceFriendlyName
    $m.DeviceType = $Device.DeviceType
    $m.DeviceUserAgent = $Device.DeviceUserAgent
    $m.FirstSyncTime = $Device.FirstSyncTime
    $m.LastSuccessSync = $Device.LastSuccessSync

    #add the temporary object to the array
    $stats += $m
    }
    }

    #format and display
    $stats | ft * -Autosize | Out-String -Width 10000 | out-file c:\_combinesList4.csv

     

    This is an example of the result

    Seinfeld, Jack jack HTC Radar 4G WP MSFT-WP/7.10.7720 12/8/2011 11:15:40 PM 12/23/2011 3:08:57 PM
    Seinfeld, Jack jack HTC Radar 4G WP MSFT-WP/7.10.7720 12/8/2011 11:15:40 PM 12/23/2011 3:08:57 PM
    Seinfeld, Jack jack HTC Radar 4G WP MSFT-WP/7.10.7720 12/8/2011 11:15:40 PM 12/23/2011 3:08:57 PM
    Seinfeld, Jack jack HTC Radar 4G WP MSFT-WP/7.10.7720 12/8/2011 11:15:40 PM 12/23/2011 3:08:57 PM

    However, my user jack seindfield have 4 different devices

    [PS] C:\scripts>Get-ActiveSyncDeviceStatistics -mailbox jack |ft deviceid,deviceuseragent,lastsuccesssync

    DeviceID DeviceUserAgent LastSuccessSync
    -------- --------------- ---------------
    ApplDLXG138JDFHW Apple-iPad2C1/812.1 2/4/2012 12:30:15 AM
    Appl321200XTEDG Apple-iPhone2C1/901.334 2/2/2012 5:45:43 PM
    Appl7R125RU1A4S Apple-iPhone3C1/901.405 1/10/2012 8:09:59 AM
    362E208BF5DEFBB5237745260382060F MSFT-WP/7.10.7720 12/23/2011 3:08:57 PM

     

    Why the script seems to be taking only the results from one device, and displaying the same thing 4 times ???

    Help, i'm a complete newb with this kind of powershell reports.

    Monday, February 6, 2012 7:39 PM

Answers

  • Try adding Identity to the list of properties:

    Select-Object DeviceFriendlyName,Identity,DeviceType,DeviceUserAgent,FirstSyncTime,LastSuccessSync
    


    Richard Mueller - MVP Directory Services

    • Marked as answer by IamMred Sunday, February 12, 2012 5:10 AM
    Saturday, February 11, 2012 2:01 AM

All replies

  • This is the exact same thing without all of the nonsense attached.

    Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"} | 
        foreach-Object{
             Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity |
                 Select-Object DeviceFriendlyName,DeviceType,DeviceUserAgent,FirstSyncTime,LastSuccessSync
        }| Export-Csv c:\_combinesList4.csv
    
    
    #--end

    We just need to pass teh results from one to the next and select teh propeties reqquired.  We then send it to the Export-CSv command.  All of the rest is unnecessary and will never work.


    ¯\_(ツ)_/¯




    • Edited by jrv Tuesday, February 7, 2012 1:01 AM
    Tuesday, February 7, 2012 12:57 AM
  • Thanks jrv, how do i add the user the device belongs to ?

    This is what i get with the above script, i'm trying to setup a report for billing, hence the need to have a name or user associated with all the devices.

    "DeviceFriendlyName","DeviceType","DeviceUserAgent","FirstSyncTime","LastSuccessSync"
    ,"iPhone","Apple-iPhone3C1/812.1","10/7/2011 6:20:50 PM","2/7/2012 1:30:17 PM"
    ,"iPhone","Apple-iPhone3C1/901.405","12/15/2011 8:21:06 PM","2/7/2012 5:08:54 PM"
    ,"iPhone","Apple-iPhone3C1/810.2","8/12/2011 5:12:57 PM","2/7/2012 5:21:18 PM"

    Tuesday, February 7, 2012 5:33 PM
  • Try adding Identity to the list of properties:

    Select-Object DeviceFriendlyName,Identity,DeviceType,DeviceUserAgent,FirstSyncTime,LastSuccessSync
    


    Richard Mueller - MVP Directory Services

    • Marked as answer by IamMred Sunday, February 12, 2012 5:10 AM
    Saturday, February 11, 2012 2:01 AM
  • I was receiving errors with:

    "pipeline not executed because a pipeline is already executing"

    I found I had to modify the script to be:

    $devices = Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"}
    $devices | foreach-Object{
             Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity |
                 Select-Object DeviceFriendlyName,Identity,DeviceType,DeviceUserAgent,FirstSyncTime,LastSuccessSync
        }| Export-Csv c:\scripts\_activesyncdevices.csv

    Monday, May 13, 2013 4:40 PM