Solved

need to change user properties in AD

Posted on 2011-03-22
7
713 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
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…

943 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

4 Experts available now in Live!

Get 1:1 Help Now