Author Posts

January 1, 2012 at 12:00 am

by Awaneendra at 2012-11-18 23:39:37

Hello Friends,

How do I remove the first row from a csv file which is nothing but a heading row using Powershell ?

I have another question. I have a Windows NT Command Script which is prepared by someone else. I am not sure about the extension of this file whether its a .bat or .cmd file. This file contains csvde command which is pulling some user info from AD. I am unable to run it in powershell. I tried many things but to no avail. Any suggestion would be highly appreciated.

Thanks,
Awaneendra

by Infradeploy at 2012-11-19 05:35:28

run the export-csv cmdlet with the -notypeinformation parameter

Why would you run a cmd in powershell? You'd use command prompt. You would have to rewrite it in powershell if you want cmdlets integrated

by Awaneendra at 2012-11-19 19:31:24

Thank you very much Infradeploy !!! I will try it.

by Awaneendra at 2012-11-20 01:13:49

Its not working. Here is the line of code which I am using —
Import-Csv D:\PS\abc.csv | select name, mail,id | Export-Csv -path D:\PS\temp\converted.csv -NoTypeInformation

When I open the converted file in MS Excel, I can still see the first row with name, mail and id which I do not want..
Any suggestion ?

by Infradeploy at 2012-11-20 03:03:48

ah, you want to remove the header.
An export-csv always includes the header am affraid

You can remove it later in your code by:
$csvfile = "D:\PS\temp\converted.csv"
Import-Csv D:\PS\abc.csv | select name, mail,id | Export-Csv -path $csvfile -NoTypeInformation
(Get-Content $csvfile | Select-Object -Skip 1) | Set-Content $csvfile