Unable to do export-csv from an empty .txt file RRS feed

  • Question

  • Hi Team,
    I am trying to create a csv file from an empty text file.The csv file should get created with only headers as no data present in text file but my code is creating a complete blank csv file without header.Anything missing in below code ?


     import-csv -Path "C:\Powershell-Work\EmtyTest.txt" -Header Date,Time,'R Site',Status,Comments |
    Select-Object 'Process Date',Date,Time,'R Site',Status,Comments| 
    Export-csv -path "C:\Powershell-Work\EmtyTest.csv" -NoTypeInformation

    Thursday, April 5, 2018 6:27 AM

All replies

  • Hi,

    What do you really want to achieve?

    Your logic makes no sense in my opinion.

    Thursday, April 5, 2018 6:59 AM
  • Close but ...

    Try this:

    '' | Select-Object 'Process Date',Date,Time,'R Site',Status,Comments| 
            Export-csv C:\Powershell-Work\EmtyTest.csv -NoTypeInformation


    Thursday, April 5, 2018 7:04 AM