• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

add a comment in active directory using power shell scripts

HI guys,

I need to run a script, add a comment in each user profile in AD 2008 in description field .this will be using a csv file

Is any way I can do that ?

1 Solution
Joseph MoodyBlogger and wearer of all hats.Commented:
That isn't possible...

Just kidding! Can you share the format of your CSV? If not, this script should get your started:

$CSV = import-csv .\users.csv

foreach ($User in $CSV){
Get-QADUser $User.Username | Set-QADUser -Description $User.Comment}

Open in new window

It assumes that your CSV has two columns. One with a username and the other with a comment. It also uses the Quest AD cmdlets.
Darrell PorterEnterprise Business Process ArchitectCommented:
I would suggest reading
which discusses updating AD User accounts from a CSV file.

You will need to download the ActiveRoles powershell addon from
Will SzymkowskiSenior Solution ArchitectCommented:
You can use Native Powershell commands to accomplish this. Use the below syntax...

CSV File should look like below...
sAMAccountName             Description
jsmith                                    info1
ptooth                                    test description
miked                                     hr dept

Import-module activedirectory
$ModUser = import-csv "c:\youCSVhere.csv"
foreach ($user in $ModUser) {
Set-ADUser -Identity $User.sAMAccountName -description $User.Description

Open in new window

RabihhajAuthor Commented:
Hi will,

Could you please explain each line, 5 years ago did c++.
I would like to learn ps.

Thanks Rabih
Will SzymkowskiSenior Solution ArchitectCommented:
See below...
line1 = importing the active directory module into the powershell session
line2 = creating a variable for importing the csv file into the powershell session
line3 = foreach user in the csv file
line4 = Bind $user to sAMAccountName (heading in csv file)
line5 = Bind $user to Description (heading in the csv file)
line6 = set the AD user description foreach object in the csv file
line7 = closing bracket

The command runs individually for each user you put in the csv file.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now