Updating custom attributes for a user via powershell

Hi All,

I need to automate the process of updating custom attributes for users from Powershell. the attributes I need to update are Ext attribute 11, 5, 6, 8, mail, mail nickname, target address, proxyaddresses. It needs to be something like when I enter the .ps1 file location, it asks me for a logon name and as soon as I enter the logon name in powershell it updates the mentioned custom attributes based on the static data of the user.

e.g. $samaccountname = read-host “Username:”

set-aduser $.samaccountname -mail ($.givenname + "" + $.sn + “@abc.com”)

7 Spice ups

OK, so what have you tried so far?

This is what I use in one of my scripts, granted I’m pulling all of the users from an OU and updating them, so you’ll probably need something a little different, but maybe give you an idea as to what is wrong.

Get-ADUser -filter * -searchbase “ou=DomainUsers,dc=contoso,dc=com” | Set-ADUser -replace @{ExtensionAttribute2=“New Value”}

2 Spice ups

Which leads to a good question–at least I think it’s good–where is this updated information coming from? When you update a user are you setting all of these attributes to the exact same thing? Are you going to calculate them or pull them from a file? How’s the file getting updated?

2 Spice ups

These are the attributes which I would like to update for a user. At this time, we update these attributes manually through ADSIEdit.msc or import from the csv but preparing a csv each time for a new set of users is really time consuming. I need a script which should ask for a Lan ID/ samAccountName and upon entering LAn Id, custom attributes should update automatically. Values like employeeID, FirstName, Lastname, Logonname are already there in AD. Rest will be put in the script. Here is the example which should work for updating mail field in adsi for a user. I am clueless on updating rest of the attributes.

$samaccountname = read-host “Username:”

set-aduser $.samaccountname -mail ($.givenname + "" + $.sn + “@abc.com”)

=======================================================================

extensionAttribute11: MSOMailbox

abcUniversalID: xyz.person.employeeID

mail:[email protected]

mailNickname:firstname_lastname

extensionAttribute8:MBX=10GB;TYPE=EP1D;REG=NA;

extensionAttribute5: 123456

extensionAttribute6:UL=US|Conf=2|

targetAddress: SMTP:[email protected]

proxyAddresses:

smtp:[email protected]

SMTP:[email protected]

smtp:[email protected]

Martin is right. In your original post you mention, “…as soon as I enter the logon name in powershell it updates the mentioned custom attributes based on the static data of the user.” “Static data of the user” may mean something to you, but it’s not a standard term and leaves the rest of us scratching our head.

Hey Bob !! Sorry for the confusion. I’ve replied to Martin in a more precised way. Hope that works. I am quite new to powershell and till now I am proficient in doing only small jobs through powershell like provisioning multiple users or groups in AD/ setting the expiration date/ updating group memberships etc that too by importing values from csv. This time I do not want to utilize csv as its very time consuming to prepare csv file with such bulky user attributes. Please excuse for my English.

No worries about being a newbie. We all have to start somewhere. Take some time to go through this thread on PowerShell resources:

http://community.spiceworks.com/topic/399521-learn-powershell

Also, Get-Help is probably your very best friend. Some of the best examples for PowerShell use are contained within PowerShell’s own help files. Be sure to run Update-Help from an elevated PowerShell window every month or so to make sure you have the latest versions.

Followed closely by Get-Member.

2 Spice ups