[英]How can I add data, insert rows and delete columns in a CSV file using powershell and then save it?
I have a big CSV file with lots of columns and lots of data, now all I am looking to do is delete few of those columns and also insert a row at the very top for the remaining columns and give new column headings. 我有一个很大的CSV文件,其中包含许多列和大量数据,现在我要做的就是删除其中一些列,并在其余列的最上方插入一行,并给出新的列标题。
Example of the CSV file I have and would like to import it in PowerShell: 我拥有的CSV文件示例,想将其导入PowerShell中:
Server A January C:drive Medium Security Logged
Server A March D:drive High Security Logged
Server B March D:drive High Audit Logged
Server B May F:drive Low Audit Logged
Server C May E:drive Low Audit Logged
And I want to use PowerShell/script to get an output like this: 我想使用PowerShell /脚本获取如下输出:
Month Drive Alert
January C:drive Medium
March D:drive High
March D:drive High
May F:drive Low
May E:drive Low
So basically again, 1) removing unwanted columns. 所以基本上还是这样,1)删除不需要的列。 2) inserting a new row, at the very top. 2)在最上方插入新行。 3) adding new data to the new row. 3)将新数据添加到新行。 4) finally exporting the CSV file. 4)最后导出CSV文件。
Thanks for the help guys :) 谢谢你们的帮助:)
try this 尝试这个
$fileContent=import-csv C:\temp\ddddd.csv -Delimiter ";" -Header Server, Month, Drive, Alert, security, Log | select Month, Drive, Alert
$newRow = New-Object PsObject -Property @{ Month = 'December' ; Drive = 'X:drive' ; Alert='Low'}
$fileContent += $newRow
$fileContent | export-csv C:\temp\ddddd2.csv -NoType
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.