Solved

need to change user properties in AD

Posted on 2011-03-22
7
728 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

We recently had an issue where out of nowhere, end users started indicating that their logins to our terminal server were just showing a "blank screen." After checking the usual suspects -- profiles, shell=explorer.exe in the registry, userinit.exe,…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
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…

821 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