Author Posts

January 1, 2012 at 12:00 am

by yarg at 2013-03-07 08:50:17

Hi all,

I currently have these 2 lines which generate a pretty comprehensive list of all AS devices in Exchange 2010:

$UserList = Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"} | Get-Mailbox
$UserList | foreach {Get-ActiveSyncDeviceStatistics -Mailbox $_.Alias} | export-csv -path c]

The problem is that the resulting csv does not contain a nicely formatted list of usernames, only the mailbox identity which, while it contains the user name, is not easy to read or put in a report. The "get-casmailbox.... | get-mailbox" portion of the script does return the user name, but then piping that output to the get-activesyncdevicestatistics command loses it. Is there someway to link/combine the 2 commands/outputs so that we end up with a list of users, the activesync devices that have connected to their mailbox and the last successful sync time?

I hope that makes sense and thanks in advance!
G

by ArtB0514 at 2013-03-07 09:17:16

Since you're using Exchange 2010, why not just do this?

Get-ActiveSyncDevice | Get-ActiveSyncDeviceStatistics | Export-Csv "C:\Temp\Filename.csv" -NoTypeInformation

by yarg at 2013-03-08 01:11:00

Thanks for the suggestion; unfortunately that command results in exactly the same output as my original script....

by kittH at 2013-03-08 06:08:54

So you want some of the output from the first object, and some from the second. The best way I know to do that is to create your own object with exactly the properties you're interested in.

$UserInfo = @()
$UserList = Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"} | Get-Mailbox
Foreach ($User in $Userlist)
{
$Devices = Get-ActiveSyncDeviceStatistics -Mailbox $User.Alias
Foreach($Device in $Devices)
{
$UserInfo += [pscustomobject]@{Name=$User.Name;DeviceType=$Device.DeviceType;DeviceID=$Device.DeviceID;DeviceOS=$Device.DeviceOS}
}
}
$UserInfo | Export-CSV -path C:\filename.csv -NoTypeInformation

I chose a few properties to put into the custom object to start with, but you can add any other properties you want from either of the objects we're using ($User or $Device), just add them with Name=Value with semicolon in between.

Also, I added a second loop for devices, since in my environment I was finding users with multiple devices which was breaking the CSV export.

by John.A.Mello at 2013-03-12 10:57:20

Adding to kittH's excellent example, I had the same problem and used the following Power Shell Magazine Article to help figure out which custom object creation technique worked best for me.

by yarg at 2013-03-19 02:28:40

Thanks to both of you for your replies and suggestions! Sorry for the delay in replying but I was out on holiday...
I took Kitt's example, saved it as a .ps1 and then ran it. A sample of the output is below:

IsReadOnly IsFixedSize IsSynchronized Keys Values SyncRoot Count
FALSE FALSE FALSE System.Collections.Hashtable+KeyCollection System.Collections.Hashtable+ValueCollection System.Object 4
FALSE FALSE FALSE System.Collections.Hashtable+KeyCollection System.Collections.Hashtable+ValueCollection System.Object 4
FALSE FALSE FALSE System.Collections.Hashtable+KeyCollection System.Collections.Hashtable+ValueCollection System.Object 4
FALSE FALSE FALSE System.Collections.Hashtable+KeyCollection System.Collections.Hashtable+ValueCollection System.Object 4
FALSE FALSE FALSE System.Collections.Hashtable+KeyCollection System.Collections.Hashtable+ValueCollection System.Object 4

Am I missing something? Was I supposed to edit something in the code (other than the output filename/location)?

Thanks!
G

by kittH at 2013-03-19 09:29:40

What version of powershell are you running? (You can check with Get-Host)

And to confirm, you're running in a session connected to the exchange management shell?