Hello all,
I would like ot know if i can take 2 columns from 1 CSV file to create a parameter response in a powershell command.
For example, I have a CSV file containing Ad user data which is ot be used to create accounts.
We have givenname and surname fields.
In the context of this example I want to create form those 2 fields a fullname without the need for an additional column in the CSV file.
I have tried adding to the new-aduser command -name $_.givenname$_.surname however this didn't work.
Is it possible to combine 2 fields in this way or even to combine a string entered into the script with a column from the CSV? (such as a profile path like \\server01\users\$_.samaccountname)
Try this:
-Name "$($_.givenname) $($_.surname)"
Perfect. Thanks very much.
Actually, I seem to be having a problem with this.
the command runs ok but it doesn't give any output. I'm not sur eif it makes any different but the CSV is not piped into the full command. I've added the contents of the CSV to a variable as follows as a test:
$userlist = import-csv c:\Users.csv $output123 = "$($userlist.givenname) $($userlist.surname)"$output123
That's not a proper test. You need to pipe $userlist and use $_ (a current pipeline object):
import-csv .\test.csv | foreach { "$($_.firstcolumn) $($_.secondcolumn)" }
the script I have written doesn't have the CSV piped in though as there's a number of actions it performs on the same set of data.
Is it only possible to merge columns when piped in to the command then?