Solved

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

Posted on 2014-12-26
6
205 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
  • 3
  • 2
6 Comments
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 400 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 68

Assisted Solution

by:Qlemo
Qlemo earned 100 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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 68

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now