Powershell: Reading in a column from a .CSV file and then adding a specific string to the beginning and exporting again -
i'm attempting write script read in csv generated querying ad user information (that part done) allow me add string beginning of each value of column in csv file , export it.
for instance have csv file:
"displayname","office"
bob,7142
janet,8923
santaclaus,0912
niccage,0823
i want take each entry "office", add string "bug" before , export out. modified csv should like:
"displayname","office"
bob,bug7142
janet,bug8923
santaclaus,bug0912
niccage,bug0823
at point, i've been attempting read in "office" column , displaying "write-host". idea being if can maybe can create new variable like:
$bug = "bug" $newvar = $bug$office
which second csv file. extremely new powershell scripting.
the attempts i've made far these:
attempt #1:
$userlist = import-csv c:\users\username\csv.csv $userlist | foreach-object ($_.office) { $userlist }
attempt #2:
$projectname = import-csv c:\users\username\csv.csv | % {$_.office} $bug = "bug" $projectname | foreach-object ($_) {$projectname}
attempt #3:
$userlist = import-csv c:\users\username\csv.csv #foreach ($office in $userlist) { #write-host $userlist.office #}
attempt #4:
import-csv "c:\users\username\csv.csv" -header ("displayname","office","whencreated","emailaddress") | select-object office | export-csv -path c:\users\username\test.csv
i have gotten read out office numbers before using foreach-object loop structure never stops reading out office numbers that's unhelpful.
i think i'm going in right direction, can't figure out how modify column this.
instead of trying extract office
column, pipe full data set (all columns) foreach-object
, change value of office
property , pipe export-csv
:
$prefix = "bug" import-csv .\file.csv | foreach-object { $_.office = $prefix + $_.office $_ } | export-csv .\file_modified.csv -notypeinformation
Comments
Post a Comment