PowerCLI

 View Only
  • 1.  Converting Out-file output to a .CSV file

    Posted Jul 01, 2011 09:34 AM

    Hello everyone,

    I was wondering if it would be possible to convert the output of the out-file cmdlet into a .csv file.  When I use out-file it creates a text file that puts each object on it's own row.

    For example, the text file would be:

    Server2

    Server3

    Server4

    I'd like to convert this .txt file to a .csv file that would be:

    Server2, Server3, Server4, etc

    I've tried using the Export-csv cmdlet instead of the out-file cmdlet but I can't seem to get it to work, so instead I was wondering if it would be possible to convert the text using a pre-made PowerCLI command or some type of script line to remove and replace characters and delimiters.

    Thanks very much for any help or assistance that anyone can give.

    Best



  • 2.  RE: Converting Out-file output to a .CSV file

    Posted Jul 01, 2011 03:29 PM

    Try something like this

    Get-Content "C:\mytext.txt" | Export-Csv "C:\mycsv.csv" -NoTypeInformation -UseCulture


  • 3.  RE: Converting Out-file output to a .CSV file

    Posted Jul 04, 2011 09:11 AM

    Hello LucD,

    Thanks for your reply.  It does create a .csv file but for a txt file that has this:

    Server2

    Server3

    Server4

    the resulting output .csv file contains this:

    "PSPath","PSParentPath","PSChildName","PSDrive","PSProvider","ReadCount","Length"
    "C:\scripts\vms.txt","C:\scripts","vms.txt","C","Microsoft.PowerShell.Core\FileSystem","1","7"
    "C:\scripts\vms.txt","C:\scripts","vms.txt","C","Microsoft.PowerShell.Core\FileSystem","2","7"
    "C:\scripts\vms.txt","C:\scripts","vms.txt","C","Microsoft.PowerShell.Core\FileSystem","3","7"

    Would there be some type of setting I need to change to make it just bring the text from the txt file?

    Best



  • 4.  RE: Converting Out-file output to a .CSV file
    Best Answer

    Posted Jul 04, 2011 10:02 AM

    Oops, my mistake.

    See if this works for you

    (Get-Content "C:\text.txt" | %{"'$_'"}) -join ',' | Out-File "C:\csv.csv"


  • 5.  RE: Converting Out-file output to a .CSV file

    Posted Jul 11, 2011 07:45 AM

    Hello Luc,

    That works perfectly.  Thanks so much again for your help.

    Best