Hi Guys,<\/p>\n

Advertisement

I am very new to Powershell and i am currently struggling on writing a script that will import information from a CSV.<\/p>\n

Advertisement

Column A has a header of ‘samaccountname’ and column b has a header of ‘employeeNumber’.<\/p>\n

I am looking to update all ‘samaccountnames’ with the 'employee number from column B.<\/p>\n

I know this is probably something simple. I had success yesterday just importing information from a CSV with the script Import-csv “filename.csv” | %{ add-adgroupmember “groupname” -members $_.samaccountname }<\/p>\n

But i cant seem to work out how to make powershell update all of column A with column B. I hope that makes sense.<\/p>\n

Sam<\/p>","upvoteCount":3,"answerCount":12,"datePublished":"2019-09-03T12:41:37.000Z","author":{"@type":"Person","name":"spiceuser-6qogk","url":"https://community.spiceworks.com/u/spiceuser-6qogk"},"acceptedAnswer":{"@type":"Answer","text":"

\n
\n
<\/div>\n\"\" samuel.bennett:<\/div>\n
\n

Hi Guys,<\/p>\n

Column A has a header of ‘samaccountname’ and column b has a header of ‘employeeNumber’.<\/p>\n

I am looking to update all ‘samaccountnames’ with the 'employee number from column B.<\/p>\n<\/blockquote>\n<\/aside>\n

$users=Import-Csv c:\\filename.csv\nforeach($user in $users){\nGet-Aduser $user.samaccountname|set-aduser -employeeid $user.employeeNumber\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-09-03T13:01:36.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/6","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},"suggestedAnswer":[{"@type":"Answer","text":"

Hi Guys,<\/p>\n

I am very new to Powershell and i am currently struggling on writing a script that will import information from a CSV.<\/p>\n

Column A has a header of ‘samaccountname’ and column b has a header of ‘employeeNumber’.<\/p>\n

I am looking to update all ‘samaccountnames’ with the 'employee number from column B.<\/p>\n

I know this is probably something simple. I had success yesterday just importing information from a CSV with the script Import-csv “filename.csv” | %{ add-adgroupmember “groupname” -members $_.samaccountname }<\/p>\n

But i cant seem to work out how to make powershell update all of column A with column B. I hope that makes sense.<\/p>\n

Sam<\/p>","upvoteCount":3,"datePublished":"2019-09-03T12:41:37.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/1","author":{"@type":"Person","name":"spiceuser-6qogk","url":"https://community.spiceworks.com/u/spiceuser-6qogk"}},{"@type":"Answer","text":"

Welcome!<\/p>\n

If you post code, please use the ‘Insert Code’ button. Please and thank you!
\nPLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a> .<\/p>\n

\"codebutton_small.png\"<\/p>","upvoteCount":0,"datePublished":"2019-09-03T12:43:56.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"

\n
\n
<\/div>\n\"\" samuel.bennett:<\/div>\n
\n

update all of column A with column B<\/p>\n<\/blockquote>\n<\/aside>\n

that’s a bit weird but sure can be done.<\/p>\n

$csv = import-csv $CSVFile\n\n$csv_new = \nforeach($line in $csv){\n    $line.columnA = $line.columnB\n}\n\n$csv_new | export-csv NewCSVFile.csv\n<\/code><\/pre>\n

something like so. I am not sure if I’m addressing what you actually want to do.
\nYou have to use the actual column name, rather than ‘columnA/B’<\/p>","upvoteCount":1,"datePublished":"2019-09-03T12:45:46.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"

\n
\n
<\/div>\n\"\" samuel.bennett:<\/div>\n
\n

Hi Guys,<\/p>\n

I am very new to Powershell and i am currently struggling on writing a script that will import information from a CSV.<\/p>\n

Column A has a header of ‘samaccountname’ and column b has a header of ‘employeeNumber’.<\/p>\n

I am looking to update all ‘samaccountnames’ with the 'employee number from column B.<\/p>\n

I know this is probably something simple. I had success yesterday just importing information from a CSV with the script Import-csv “filename.csv” | %{ add-adgroupmember “groupname” -members $_.samaccountname }<\/p>\n

But i cant seem to work out how to make powershell update all of column A with column B. I hope that makes sense.<\/p>\n

Sam<\/p>\n<\/blockquote>\n<\/aside>\n

so you have imported a CSV file and added users to groupname.<\/p>\n

now you want to manipulate your CSV file by copying column B to column A?<\/p>","upvoteCount":0,"datePublished":"2019-09-03T12:47:04.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/4","author":{"@type":"Person","name":"rinomardo2","url":"https://community.spiceworks.com/u/rinomardo2"}},{"@type":"Answer","text":"

Do you want to add employee numbers to the user objects in AD by pulling the information from your CSV file?<\/p>","upvoteCount":0,"datePublished":"2019-09-03T12:48:53.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/5","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"

Thanks For our responses guys. I believe i may have confused the situation by adding in the Powershell i ran yesterday. That was just an example of how i improted from csv. My knowledge is very minimal at the moment but i am enjoying learning \":slight_smile:\"
\n@jitensh<\/a> ​ i think that is what i will need.
\nThe attribute i am updating wth the employee number is called employee number the users AD attributes. My company chose to go with employee number rather than employee ID. So will this modification to your script work for that purpose?
\n$users=Import-Csv c:\\filename.csv foreach($user in $users){ Get-Aduser $user.samaccountname|set-aduser -employeenumber $user.employeeNumber.<\/p>\n

If i wish to run that as a test do i just add -whatif or do i need to pipe it first.
\nThanks for all of your comments guys. Its a really helpful community here \":slight_smile:\"
\nSam<\/p>","upvoteCount":0,"datePublished":"2019-09-03T13:50:44.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/7","author":{"@type":"Person","name":"spiceuser-6qogk","url":"https://community.spiceworks.com/u/spiceuser-6qogk"}},{"@type":"Answer","text":"

\n
\n
<\/div>\n\"\" samuel.bennett:<\/div>\n
\n

If i wish to run that as a test do i just add -whatif or do i need to pipe it first.<\/p>\n<\/blockquote>\n<\/aside>\n

You can add -WhatIf, because it is a common parameter available to every native Powershell command.<\/p>","upvoteCount":0,"datePublished":"2019-09-03T13:54:47.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/8","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"

Thanks for your help Guys. That will be my little project for tonight when i am at home.<\/p>","upvoteCount":0,"datePublished":"2019-09-03T14:10:59.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/9","author":{"@type":"Person","name":"spiceuser-6qogk","url":"https://community.spiceworks.com/u/spiceuser-6qogk"}},{"@type":"Answer","text":"

your company may call it employee number but its employee id in AD.<\/p>","upvoteCount":1,"datePublished":"2019-09-03T14:27:29.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/10","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"

@jitensh<\/a> ​ The field i was updating is employeenumber as that is what my company decided to use.
\nBut thank you for your script it worked perfectly.
\nSam<\/p>","upvoteCount":0,"datePublished":"2019-09-04T08:03:40.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/11","author":{"@type":"Person","name":"spiceuser-6qogk","url":"https://community.spiceworks.com/u/spiceuser-6qogk"}},{"@type":"Answer","text":"

Please close the topic but marking the answer as best answer> select answer> manage> best answer<\/p>","upvoteCount":0,"datePublished":"2019-09-04T09:21:03.000Z","url":"https://community.spiceworks.com/t/how-to-use-csv-to-import-employee-number-in-powershell/728310/12","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}}]}}