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
Oops, my mistake.
See if this works for you
(Get-Content "C:\text.txt" | %{"'$_'"}) -join ',' | Out-File "C:\csv.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-Content "C:\mytext.txt" | Export-Csv "C:\mycsv.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
Oops, my mistake.
See if this works for you
(Get-Content "C:\text.txt" | %{"'$_'"}) -join ',' | Out-File "C:\csv.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Luc,
That works perfectly. Thanks so much again for your help.
Best