Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Adding columns to an existing CSV

$
0
0
Import-CSV original.csv |
ForEach-Object {

  $data1 = 'whatever'
  $data2 = 'hello'

  $_ | 
  Add-Member -MemberType NoteProperty -Name ColumnA -Value $data1 -PassThru |
  Add-Member -MemberType NoteProperty -Name ColumnB -Value $data2 -PassThru

} |
Export-CSV revised.csv

Something vaguely like that. You can access the current columns via $_, e.g., “$user = Get-ADUser -Identity $_.samaccountname” if the current CSV has a samaccountname column. Import-CSV brings in the CSV as objects, Add-Member adds properties to those objects, and Export-CSV writes the revised objects back to a CSV.


Viewing all articles
Browse latest Browse all 13067

Trending Articles