![](/img/trans.png)
[英]How can I update more data rows in Active Directory from a csv file using Powershell?
[英]How can I add data, insert rows and delete columns in a CSV file using powershell and then save it?
我有一個很大的CSV文件,其中包含許多列和大量數據,現在我要做的就是刪除其中一些列,並在其余列的最上方插入一行,並給出新的列標題。
我擁有的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
我想使用PowerShell /腳本獲取如下輸出:
Month Drive Alert
January C:drive Medium
March D:drive High
March D:drive High
May F:drive Low
May E:drive Low
所以基本上還是這樣,1)刪除不需要的列。 2)在最上方插入新行。 3)將新數據添加到新行。 4)最后導出CSV文件。
謝謝你們的幫助:)
嘗試這個
$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.