Your PowerGUI Community: Simplify your PowerShell related GUI and script editing needs.


powershell export to csv

This question is answered

Hello,

We need to integrate a faxsolution in our network. Our need is to export all usermailboxes and shared mailboxes in the following format Firstname,Lastname,email

I used this powershell command to reach the solution, but it's not working properly.

Get-QADUser | where {Get-Mailbox -RecipientTypeDetails "Sharedmailbox","UserMailbox"} | Select-Object Firstname,Lastname,email | Export-Csv "C:\import_orig03.txt" -Encoding "Unicode"

What am I doing wrong? What needs to be done so that I only get a list of these types of mailboxes?

Best regards,

Philippe

Verified Answer
  • The problem is that you get all users and foreach user you get ALL mailbox objects.

    Try this way:

    Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox,UserMailbox | Get-User | Select-Object FirstName,LastName,WindowsEmailAddress

All Replies
  • The problem is that you get all users and foreach user you get ALL mailbox objects.

    Try this way:

    Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox,UserMailbox | Get-User | Select-Object FirstName,LastName,WindowsEmailAddress

  • Hello Shay,

    Thanx for the advice and solution. As a novice in powershell I still need a lot to learn...

    Best regards,

    Philippe
  • hello, I have an issue where my export will not comeout right when I export the following. The text file works great, but the csv, is not even close. I am using exchange 2010 and excel 2010. Can anyone help with this???

    Oh, I needed to ass the email address as well

    Get-MailboxStatistics -Server 'myserver' | Where {$_.DisconnectDate -eq $null -AND $_.DisplayName -notlike "SystemMailbox*"} | Sort DatabaseName, DisplayName | FT -AutoSize DatabaseName, DisplayName, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, ItemCount | Export-csv d:\databaseCSV\testing.csv

    Its exporting wrong, the texts file looks great though

    Love the logo on the maini page here, my kid wants to get one, lol

    All help would be greatly appreaciated
    Duramaxster

  • Replace FT with select-object. FT creates formatting instructions (not objects):

    Get-MailboxStatistics -Server myserver | `
    Where {$_.DisconnectDate -eq $null -AND $_.DisplayName -notlike "SystemMailbox*"} | `
    Sort DatabaseName, DisplayName | `
    Select-Object DatabaseName, DisplayName, @{expression={$_.totalitemsize.value.ToMB()};label='Size(MB)'},ItemCount | `
    Export-csv d:\databaseCSV\testing.csv