Solved

need to change user properties in AD

Posted on 2011-03-22
7
722 Views
Last Modified: 2012-05-11
I need a powershell script to modify the following attributes in AD , this is what i have but it doesnt work if someone can see what i need to do . I have a csv file with samaccount and description fields only i need to do the rest but i need to know how to set -qaduser identity it hangs at this point


$users = 'c:\setqadtestfile.csv'

Import-Csv $users | `
foreach {
set-qaduser -Identity  $_.MySamAccount `
-Decription $_.Mydescription `
-Title `
-StreetAddress `
-Company  `
-Office  `
-Postalcode  `
-City  `
-StateOrProvince  `
-PhoneNumber  `
}
0
Comment
Question by:gd6627
  • 5
  • 2
7 Comments
 
LVL 12

Expert Comment

by:GusGallows
ID: 35192513
You should be able to do this using a simple Set-User command with the ADSI extension. It would look something like this (assuming your headers in your CSV are MySamAccount,Mydescription):

$users = import-csv 'c:\setqadtestfile.csv'

foreach ($item in $users)
{
	$Id = $item.MySamAccount
	$desc = $item.Mydescription
	$usr = get-user $id
	$usrDN = $usr.DistinguishedName
	Set-User $id -Description $desc
	$AD = [ADSI]"LDAP://$usrDN"
	$AD."description" = $desc

Open in new window

0
 
LVL 12

Expert Comment

by:GusGallows
ID: 35192523
ack, lose the Set-User line. I did not mean to keep that in there.
0
 
LVL 12

Expert Comment

by:GusGallows
ID: 35192529
Let's try that again:

$users = import-csv 'c:\setqadtestfile.csv'

foreach ($item in $users)
{
	$Id = $item.MySamAccount
	$desc = $item.Mydescription
	$usr = get-user $id
	$usrDN = $usr.DistinguishedName
	$AD = [ADSI]"LDAP://$usrDN"
	$AD."description" = $desc
	$Ad.SetInfo()
}

Open in new window

0
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

 
LVL 12

Expert Comment

by:GusGallows
ID: 35193522
If you are adding more than just the description attribute, make sure to use the attribute names as you see them in ADSI edit. For instance:
User Attribute Name                  ADSI attribute name
Title                                             title
StreetAddress                           streetAddress
Company                                   company
Office                                        physicalDeliveryOfficeName
Postalcode                                postalCode
City                                            l
StateOrProvince  `                    st
PhoneNumber                           telephoneNumber
Your header in your CSV would look like this:
MySamAccount,Mydescription,MyTitle,MyStreetAddress,MyCompany,MyOffice,MyPostalCode,MyCity,MyStateOrProvince,PhoneNumber

The code in the powershell script would looks as follows:
$users = import-csv 'c:\setqadtestfile.csv'

foreach ($item in $users)
{
	$Id = $item.MySamAccount
	$desc = $item.Mydescription
	$title = $item.MyTitle
	$address = $item.MyStreetAddress
	$company = $item.MyCompany
	$ofice = $item.MyOffice
	$zip = $item.MyPostalCode
	$city = $item.MyCity
	$state = $item.MyStateOrProvince
	$phone = $item.PhoneNumber
	$usr = get-user $id
	$usrDN = $usr.DistinguishedName
	$AD = [ADSI]"LDAP://$usrDN"
	$AD."description" = $desc
	$AD."title" = $title
	$AD."streetAddress" = $address
	$AD."company" = $company
	$AD."physicalDeliveryOfficeName" = $office
	$AD."postalCode" = $zip
	$AD."l" = $city
	$AD."st" = $state
	$AD."telephoneNumber" = $phone
	$Ad.SetInfo()
}

Open in new window

0
 

Author Comment

by:gd6627
ID: 35193615
Ok but am using cmdlets from quest  software in powergui can your script still work
0
 
LVL 12

Accepted Solution

by:
GusGallows earned 500 total points
ID: 35206987
Sorry, this script was written to work on an Exchange 2007 powershell.

It will also work in the Active Directory Module for Windows Powershell by changing the following line:
$usr = get-user $id
to
$usr=get-aduser $id"

So this will not work on a regular windows powershell without either the exchange module loaded or the AD module using the change to the one line of syntax.

I have never used the quest add-on, so I am not sure it will work with it.
Maybe if you change it to:
$usr = get-qaduser $id

As long as it returns the distinguished name as one of the attributes of the user, this script should work.
0
 

Author Closing Comment

by:gd6627
ID: 35228938
Thank you so much it work fine
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I have been working as System Administrators since 2003. I recently started working as a FreeLancer and was amazed to find out that very few people are taking full advantage of their Windows Server Machines. Microsoft Windows Server comes with so…
I was supporting a handful of Windows 2008 (non-R2) 2 node clusters with shared quorum disks. Some had SQL 2008 installed and some were just a vendor application that we supported. For the purposes of this article it doesn’t really matter which so w…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

809 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