none
Export Powershell output to CSV AND display on screen RRS feed

  • Question

  • Hi

    Within Powershell,  I sometimes export the results of a command to a CSV like so:

    get-mailboxserver Mail1 | get-mailbox > c:\mailboxes.csv

    Sometimes I like to view the display on the screen AND export to csv, does anyone know how I can do that?
    Wednesday, June 8, 2011 9:39 PM

All replies

  • get-mailboxserver Mail1 | get-mailbox | tee c:\mailboxes.csv


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Wednesday, June 8, 2011 9:55 PM
  • Great, thanks!

    So the Tee command will display the output on the screen and also export to CSV file? One further question, what if I wanted to keep adding the output of various gets to the same file, how can I specify to append? For instance:

    get-mailboxserver Mail1 | get-mailbox | tee c:\mailboxes.csv

    get-mailboxserver Mail2 | get-mailbox | tee c:\mailboxes.csv

    get-mailboxserver Mail3 | get-mailbox | tee c:\mailboxes.csv

    I run these commands seperately, but I want them all to append to the same file - c:\mailboxes.csv?

    Wednesday, June 8, 2011 10:29 PM
  • get-mailboxserver Mail1 | get-mailbox | tee -var a ; $a >>c:\mailboxes.csv


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Wednesday, June 8, 2011 10:43 PM
  • Thanks, could you explain what the below does?

    get-mailboxserver Mail1 | get-mailbox | tee -var a ; $a >>c:\mailboxes.csv

     

    Saturday, June 18, 2011 11:04 AM
  • get-mailboxserver Mail1 | get-mailbox | add-content c:\mailboxes.csv -pass

    get-mailboxserver Mail2 | get-mailbox | add-content c:\mailboxes.csv -pass

    Saturday, June 18, 2011 11:24 AM
  • That dosn't seem to work

    Anyway, I'm running

    get-mailboxserver Mail1 | get-mailbox |  out-file c:\mailboxes.txt -append

    Forget trying to write to the txt file and screen at the same time, once the above command has completed, it is possible to get the results on the screen? I guess I need to echo the results back?

    Saturday, June 18, 2011 11:28 AM