Answered by:
Import CSV into AD

Question
-
Hey Folks - Happy New Year! My boss has me working on a project to import a few attributes into AD for all of our employees. They are Department, Manager, Email and Title. I started piecing together a script of the net (because I don't know powershell that well) and then he informed me he wanted a log file to spit out what, if anything was already in AD and then show what it was changing it to. And I managed to get there... to an extent.
# Import AD Module Import-Module ActiveDirectory write-Host 'Starting to update AD Attributes.......' -ForegroundColor White # Import CSV into variable $users $users = Import-Csv -Path C:\Scripts\Powershell\users.csv foreach ($user in $users) { Write-Host $user $output = '' $u = Get-ADUser -Filter "displayName -eq '$($user.name)'" -Properties * -SearchBase "DC=------,DC=---" $output = "Found $($u.name) at $($u.sAMAccountName)`r`n" ` + "Email Address: $($u.mail) --> $($user.emailaddress)`r`n" ` + "Title: $($u.title) --> $($user.Title)`r`n" ` + "Department: $($u.department) --> $($user.department)`r`n" ` + "Manager: $($u.manager) --> $($user.manager)`r`n" Set-ADUser -EmailAddress $($user.EmailAddress) -title $($user.title) -department $($user.department) -manager $($user.manager) #Comment out to test log only $output | Out-File -FilePath "log.txt" -Append } Write-Host 'done!' -ForegroundColor Green
When I run my script, I get asked for an identity but I want it to be reading the display name off of the CSV file. If I comment out the Set-User line (to do a log only test) it works fine. I am not yet able to attach pictures (I had a screen shot of my CSV) but the headings for my CSV file are as follows: name, emailaddress, title, department, manager
If I could get finished with this project I would have time to do the powershell training I so despartely need.
Thanks all,
Tom
Thursday, December 31, 2015 1:11 PM
Answers
-
Because you need to supply an identity or a user object which you are not doing. Set-AdUser requires an identity.
$u | Set-AdUser ....
\_(ツ)_/
- Marked as answer by Tom Skubel Thursday, December 31, 2015 3:28 PM
Thursday, December 31, 2015 2:30 PM
All replies
-
What is the question? If you are getting an error please post the complete error message.
\_(ツ)_/
- Edited by jrv Thursday, December 31, 2015 1:16 PM
Thursday, December 31, 2015 1:15 PM -
Sorry about that. The question is why when I run this script am I getting asked for an identity? and what value does it want? This is the output I get when I run the script:
PS C:\Scripts\PowerShell> C:\Scripts\PowerShell\UpdateADattrib.ps1 Starting to update AD Attributes....... @{name=Buzz Lightyear; emailaddress=W; title=X; department=Z; manager=TMCGEE} cmdlet Set-ADUser at command pipeline position 1 Supply values for the following parameters: Identity:
Thursday, December 31, 2015 2:01 PM -
Because you need to supply an identity or a user object which you are not doing. Set-AdUser requires an identity.
$u | Set-AdUser ....
\_(ツ)_/
- Marked as answer by Tom Skubel Thursday, December 31, 2015 3:28 PM
Thursday, December 31, 2015 2:30 PM -
Thank you very much!Thursday, December 31, 2015 3:28 PM
-
You are welcome. Have a great new year.
\_(ツ)_/
Thursday, December 31, 2015 11:27 PM