Jump to content

Recommended Posts

Posted

I have a simple Q for you.

 

I want to add a column to an existing csv, then in that column add the same data to all cells.

 

Can someone please send me a PowerShell idea.

 

Thanks

Posted (edited)

Maybe something like this?

Import-Csv File.csv | Select-[font=inherit]Object[/font] *,@{Name=[font=inherit]'New column'[/font];Expression={[font=inherit]'ValueForNewCol'[/font]}} | Export-Csv NewFile.csv -NoTypeInformation

Edited by ThomL
typo
Posted

sorry I dont understand the COLOR use. the csv is e.g.

 

first,last

pete,white

james,cook

 

 

I want to end up with

 

first,last,role

pete,white,staff

james,cook,staff

 

 

sounds easy.

Thanks

Posted (edited)
sorry I dont understand the COLOR use. the csv is e.g.

 

first,last

pete,white

james,cook

 

 

I want to end up with

 

first,last,role

pete,white,staff

james,cook,staff

 

 

sounds easy.

Thanks

 

Had issues with posting the code to the forum, take another look at my previous post - I've updated it.

 

EDIT!

 

or here it is again with your column name and value added:

 

Import-Csv File.csv | Select-[font=inherit]Object[/font] *,@{Name=[font=inherit]'[/font]role[font=inherit]'[/font];Expression={[font=inherit]'[/font]staff[font=inherit]'[/font]}} | Export-Csv NewFile.csv -NoTypeInformation

Edited by ThomL
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...