locked
Export-CSV only exports the string length RRS feed

  • Question

  • Hi friends.

     

    I am trying to get a list of all the e-mails I have on the server, even proxy accounts, each one in a separated row.

    I tried to get this with this command

     

    get-mailbox | foreach-Object -process {$_.emailaddresses} | export-csv 'c:\file.csv' -notypeinformation

     

    but with this I only get the string lengths on the .csv file.

    I have also tried this other method, but have the same problem.

     

    get-mailbox | select -expandproperty emailaddresses | export-csv 'c:\file.csv' -notypeinformation

     

    I found it wierd, since when I only display on the screen, without writing the export-csv part, I get exactly what I want.

     

    Does anybody know how to solve this?

     

    Thanks,

    Vladimir

    Saturday, June 26, 2010 3:02 PM

Answers

  • Hi,

    Try this one-liner:

    Get-Mailbox -server MailboxServerName | Select DisplayName, @{Name=’EmailAddresses’;Expression={[string]::join(";", ($_.EmailAddresses))}} | Export-CSV C:\\EmailIDs.csv -notypeinformation

     

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    • Proposed as answer by Laeeq Qazi Friday, July 2, 2010 9:48 AM
    • Marked as answer by emma.yoyo Monday, July 5, 2010 2:23 AM
    Saturday, June 26, 2010 8:36 PM
  • get-mailbox | foreach-Object -process {$_.emailaddresses} | export-csv 'c:\file.csv' -notypeinformation

    get-mailbox | select -expandproperty emailaddresses | export-csv 'c:\file.csv' -notypeinformation

    I found it wierd, since when I only display on the screen, without writing the export-csv part, I get exactly what I want.

    Hi Vladimir,

    Do you mean if you don't add Export-Csv in these two cmdlets, the results on the display is just you want?

    Will it be meet you needs if you export the results to a txt file?

    get-mailbox | foreach-Object -process {$_.emailaddresses} >c:\file.txt


    Frank Wang
    • Marked as answer by emma.yoyo Monday, July 5, 2010 2:23 AM
    Tuesday, June 29, 2010 5:54 AM

All replies

  • On Sat, 26 Jun 2010 15:02:55 +0000, Vladimir_Magalhaes wrote:
     
    >
    >
    >Hi friends.
    >
    >
    >
    >I am trying to get a list of all the e-mails I have on the server, even proxy accounts, each one in a separated row.
    >
    >I tried to get this with this command
    >
    >
    >
    >get-mailbox | foreach-Object -process {$_.emailaddresses} | export-csv 'c:\file.csv' -notypeinformation
    >
    >
    >
    >but with this I only get the string lengths on the .csv file.
     
    The 'emailaddresses' property is an array of objects
    (SmtpProxyAddress, CustomProxyAddress, X400ProxyAddress,
    InvalidProxyAddress), and each of them have several properties of
    their own (SmtpAddress, AddressString, ProxyAddressString, Prefix,
    IsPrimaryAddress, PrefixString).
     
    So, one way to get a list of all the addresses, with their address
    types, would be:
     
    get-mailbox | foreach-Object {foreach ($a in $_.emailaddresses){write
    $a.proxyaddressstring}}
     
    If you want only SMTP addresses you could use this:
     
    get-mailbox | foreach-Object {foreach ($a in $_.emailaddresses){ if
    ($a.prefixstring -eq 'smtp') {write $a.proxyaddressstring}}}
     
    Or, if you don't want to know if the address is a primary (the address
    type would be in upper-case) or secondary (the address type would be
    in lower-case), you could use:
     
    get-mailbox | foreach-Object {foreach ($a in $_.emailaddresses){ if
    ($a.prefixstring -eq 'smtp') {write $a.addressstring}}}
     
     
     
     
     
     
     
     
     
     
     
     
     
    >
    >I have also tried this other method, but have the same problem.
    >
    >
    >
    >get-mailbox | select -expandproperty emailaddresses | export-csv 'c:\file.csv' -notypeinformation
    >
    >
    >
    >I found it wierd, since when I only display on the screen, without writing the export-csv part, I get exactly what I want.
    >
    >
    >
    >Does anybody know how to solve this?
    >
    >
    >
    >Thanks,
    >
    >Vladimir
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    • Marked as answer by emma.yoyo Monday, July 5, 2010 2:22 AM
    • Unmarked as answer by emma.yoyo Monday, July 5, 2010 2:23 AM
    Saturday, June 26, 2010 6:50 PM
  • Hi,

    Try this one-liner:

    Get-Mailbox -server MailboxServerName | Select DisplayName, @{Name=’EmailAddresses’;Expression={[string]::join(";", ($_.EmailAddresses))}} | Export-CSV C:\\EmailIDs.csv -notypeinformation

     

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    • Proposed as answer by Laeeq Qazi Friday, July 2, 2010 9:48 AM
    • Marked as answer by emma.yoyo Monday, July 5, 2010 2:23 AM
    Saturday, June 26, 2010 8:36 PM
  • get-mailbox | foreach-Object -process {$_.emailaddresses} | export-csv 'c:\file.csv' -notypeinformation

    get-mailbox | select -expandproperty emailaddresses | export-csv 'c:\file.csv' -notypeinformation

    I found it wierd, since when I only display on the screen, without writing the export-csv part, I get exactly what I want.

    Hi Vladimir,

    Do you mean if you don't add Export-Csv in these two cmdlets, the results on the display is just you want?

    Will it be meet you needs if you export the results to a txt file?

    get-mailbox | foreach-Object -process {$_.emailaddresses} >c:\file.txt


    Frank Wang
    • Marked as answer by emma.yoyo Monday, July 5, 2010 2:23 AM
    Tuesday, June 29, 2010 5:54 AM
  • Hi Vladimir,

    Any updates?


    Frank Wang
    Thursday, July 1, 2010 1:46 AM
  • Hi Vladimir,

    How about your question? Any updates?


    Frank Wang
    Friday, July 2, 2010 9:07 AM