Share via


Export-CSV mostly working but one column displays System.String[] (Exchange tracking logs)

Question

Monday, March 19, 2012 11:58 AM

Hi all,

How can I get the actual Recipients to show up in the csv output?  Outputting to a regular txt file shows them fine.

Script is as follows:

Get-ExchangeServer | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true}  | Get-MessageTrackingLog -Sender "[email protected]" | Select-Object Timestamp,ServerHostname,ClientHostname,Source,EventId,Sender,Recipients,MessageSubject | Sort-Object -Property Timestamp | Export-Csv e:\user.csv

Output is as follows:

Many thanks,

Graham

All replies (5)

Monday, March 19, 2012 12:22 PM âś…Answered | 8 votes

Hi Graham,

Because Recipients is object, mostly have one value but it could have some results.

Try that:

Get-ExchangeServer | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true}  | Get-MessageTrackingLog -Sender "[email protected]" | Select-Object Timestamp,ServerHostname,ClientHostname,Source,EventId,Sender,@{l="Recipients";e={$_.Recipients -join " "}},MessageSubject | Sort-Object -Property Timestamp  | Export-Csv e:\user.csv

Monday, March 19, 2012 12:55 PM

By Jove it works!!

A thousand thank you's Michal!  Very helpful!!

Graham


Monday, March 19, 2012 1:03 PM

Hi Michal.  I hate these horizontal scroll bars so much.  I can't see your whole answer, can't copy it to clipboard, and I find it very difficult to read a script that has to scroll horizontally.

So, based on your reputation alone, I propose yours as an answer.

Grant Ward, a.k.a. Bigteddy

What's new in Powershell 3.0 (Technet Wiki)


Thursday, November 7, 2013 5:30 AM

If I run the following without export to CSV, it looks ok.

SamAccountName,DeviceType

dsmith, {iphone, android}

But export to csv, for any user that has multiple devices I get

SamAccountName,DeviceType

dsmith, System.Object[]

Can anyone show me how to fix?

 

$mailcollection = @()
$amer = 'OU=Users,OU=AMER,DC=global,DC=xyz,DC=net'
$apac = 'OU=Users,OU=APAC,DC=global,DC=xyz,DC=net'
$emea = 'OU=Users,OU=EMEA,DC=global,DC=xyz,DC=net'
$mailboxamer = Get-Mailbox -OrganizationalUnit $amer
$mailboxapac = Get-Mailbox -OrganizationalUnit $apac
$mailboxemea = Get-Mailbox -OrganizationalUnit $emea

Foreach-Object {
$mailboxamer | %{
  $objamer = "" | Select-Object SamAccountName,DeviceType
  $objamer.SamAccountName = $_.SamAccountName
  $objamer.DeviceType = (Get-MobileDeviceStatistics -Mailbox $_.Identity).DeviceType
  $mailcollection += $objamer
}
$mailboxapac | %{
  $objapac = "" | Select-Object SamAccountName,DeviceType
  $objapac.SamAccountName = $_.SamAccountName
  $objapac.DeviceType = (Get-MobileDeviceStatistics -Mailbox $_.Identity).DeviceType
  $mailcollection += $objapac
}
$mailboxemea | %{
  $objemea = "" | Select-Object SamAccountName,DeviceType
  $objemea.SamAccountName = $_.SamAccountName
  $objemea.DeviceType = (Get-MobileDeviceStatistics -Mailbox $_.Identity).DeviceType
  $mailcollection += $objemea
}
}
$mailcollection# | Export-Csv "C:\David\test.csv"  -NoTypeInformation


Thursday, November 7, 2013 5:32 AM

Export to txt look ok, but your solution doesn't seem to work for me

$objamer = "" | Select-Object SamAccountName,@{l="DeviceType";e={$_.DeviceType -join " "}}