Solved

need to change user properties in AD

Posted on 2011-03-22
7
703 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

705 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

17 Experts available now in Live!

Get 1:1 Help Now