gd6627
asked on
need to change user properties in AD
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 `
}
$users = 'c:\setqadtestfile.csv'
Import-Csv $users | `
foreach {
set-qaduser -Identity $_.MySamAccount `
-Decription $_.Mydescription `
-Title `
-StreetAddress `
-Company `
-Office `
-Postalcode `
-City `
-StateOrProvince `
-PhoneNumber `
}
ack, lose the Set-User line. I did not mean to keep that in there.
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()
}
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,M yStreetAdd ress,MyCom pany,MyOff ice,MyPost alCode,MyC ity,MyStat eOrProvinc e,PhoneNum ber
The code in the powershell script would looks as follows:
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
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()
}
ASKER
Ok but am using cmdlets from quest software in powergui can your script still work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much it work fine
Open in new window