?
Solved

Use PS cmdlet to read a CSV file and update AD attributes

Posted on 2014-12-26
6
Medium Priority
?
212 Views
Last Modified: 2014-12-29
I have a big CSV file which contains rows and rows of information like the following:

Samaccountname, givenname, surname, telephonenumber, mail.

Please advise a PS cmdlet that reads the CSV file and update user attribute fields in AD.

Thanks.
0
Comment
Question by:nav2567
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
David Johnson, CD, MVP earned 1600 total points
ID: 40518731
#Samaccountname, givenname, surname, telephonenumber, mail
$users = import-csv c:\test\users.csv
foreach ($user in $users){
get-aduser -filter samaccountname -eq $user.samaccountname | 
    set-aduser -Surname $user.surname -GivenName $user.givenname `
        -EmailAddress $user.mail -OfficePhone $user.telephonenumber
}

Open in new window

0
 

Author Comment

by:nav2567
ID: 40519563
Thanks.  

I am getting the following error when I run the cmdlets:

Get-ADUser : A parameter cannot be found that matches parameter name 'eq'.
At line:1 char:64
+ foreach ($user in $users){get-aduser -filter samaccountname -eq <<<<  $user.samaccountname |set-aduser -Surname $use
.surname - GivenName $user.givenname -OfficePhone $user.telephonenumber
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Also, would you please let me know what exactly should the content of my CSV file contain?

Currently, it is like this:

jsmith John Smith 213-334-5566
mjane Mary Jane 213-223-4455
mmecay Mike Meccay 208-334-5566
...
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 40520510
nav2567, you need to be exact in what you provide. The data in http:#a40519563 is no CSV format, and in the original question you showed a (proper) CSV header line. The CSV should look like this:
Samaccountname, givenname, surname, telephonenumber, mail
jsmith, John, Smith, 213-334-5566,
mjane, Mary, Jane, 213-223-4455,
mmecay, Mike, Meccay, 208-334-5566,

Open in new window

Since you have not provided an email address, the cmdlet will fail. I've hence removed that from the command:
import-csv c:\test\users.csv | % {
  set-aduser $_.SamAccountName -Surname $_.surname -GivenName $_.givenname -OfficePhone $_.telephonenumber
}

Open in new window

0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:nav2567
ID: 40521209
Sorry. Let me try that again.

Thanks for your feedback.
0
 

Author Closing Comment

by:nav2567
ID: 40521277
Thanks, everyone.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40521435
Since my solution works, and the other one does not and is overly complicated, I would have expected to receive at least the majority of points.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question