Author Posts

January 1, 2012 at 12:00 am

by JennS24 at 2013-03-14 15:58:18

Hello scripting gurus,

I need a csv file listing all ActiveSync devices, the last successful sync, and the user identity. I've Googled entirely too much in the last 24 hours and nothing I find works for me, and if it does, it only shows output on the screen. I'm in Exchange 2010 but it's Office 365, I don't know if that matters.

Any suggestions? I will be eternally grateful!

by ArtB0514 at 2013-03-15 07:00:28

I don't have access to Office 365, but assuming that the standard Exchange 2010 cmdlets work, you can get information you want by doing this:

$AS = @()
$Devices = Get-ActiveSyncDevice
$Devices | foreach {
$UserName = ($_.UserDisplayName.Split('/'))[-1]
$AS += Get-ActiveSyncDeviceStatistics $_.Identity -ErrorAction SilentlyContinue | Select DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,LastSuccessSync,@{Name='User';Expression={$UserName}}
}
$AS | Export-Csv MyCsvFile.csv -NoTypeInformation

by JennS24 at 2013-03-15 13:14:06

Thank you. This took a really long time to run then returned this error many times:

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:5 char:17
+ $AS | Export-Csv < <<< c:\o365\asdevlist.csv -NoTypeInformation
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

by ArtB0514 at 2013-03-15 13:47:35

Hmmm. I didn't get any errors when I ran it against our in-house Exchange 2010 systems. Seems like there are probably some null lines in the $AS object from statistics that didn't get returned. You could verify by doing
$AS | Group DeviceType -NoElement
Also, this might fix the issue:
$AS = @()
$Devices = Get-ActiveSyncDevice
$Devices | foreach {
$UserName = ($_.UserDisplayName.Split('/'))[-1]
Try {
$Data = Get-ActiveSyncDeviceStatistics $_.Identity -ErrorAction Stop | Select DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,LastSuccessSync,@{Name='User';Expression={$UserName}}
$AS += $Data
}
Catch {}
}
$AS | Export-Csv MyCsvFile.csv -NoTypeInformation

by JennS24 at 2013-03-19 16:22:54

No errors but there were also no results in the file.

by MasterOfTheHat at 2013-03-19 20:04:25

See if this gets you started. I wrote it for 2007, but hopefully it will work on 2010.

If ((Get-PSSnapin | where {$_.Name -match "Exchange.Management"}) -eq $null)
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
}

Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"} | Get-Mailbox |
ForEach-Object {
Get-ActiveSyncDeviceStatistics -Mailbox $_ | Select-Object Identity,LastSuccessSync,DeviceID,DeviceType |
Where-Object { $_.LastSuccessSync -gt $((Get-Date).AddDays(-60)) }
}

by John.A.Mello at 2013-03-20 05:27:11

If your stil having problems you can take a look at a script I wrote to get the same information and email it as a nightly report. You can modify it to drump a CSV instead:
http://gallery.technet.microsoft.com/scriptcenter/Get-Active-Sync-devices-9bfb5116

by ArtB0514 at 2013-03-20 11:50:43

It seems that an extraneous "\" character got inserted at the end of the $Data= line in the script segment I posted. Remove it and try again to see if it works without the typo. Also, you can check a couple of things by adding some more while-processing information.
$AS = @()
$Devices = Get-ActiveSyncDevice
$dCount = $Devices.Count
$i = 1
$Devices | foreach {
$pct = [int](($i/$dCount)*100)
$UserName = ($_.UserDisplayName.Split('/'))[-1]
Write-Progress -Activity "Checking ActiveSync Devices" -Status "Processing $UserName ($i of $dCount)" -PercentComplete $pct
Try {
$Data = Get-ActiveSyncDeviceStatistics $_.Identity -ErrorAction Stop | Select DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,LastSuccessSync,@{Name='User';Expression={$UserName}}
$AS += $Data
}
Catch {}
$i++
}
"Saving $($AS.Count) device records."
$AS | Export-Csv MyCsvFile.csv -NoTypeInformation

by JennS24 at 2013-03-20 20:04:55

ArtB, you are awesome! This works almost perfectly for me! The user name I got with your script wasn't right (because we're in Office 365), but I added "Identity" to the output I want and got something I can use. I've fought with this for a week and it's very satisfying to finally get it. Maybe I can sleep tonight! Thank you so much. As promised, I am eternally grateful. 🙂