Share via


AD attribute update of bulk user object from TXT file which contains samaccountname

Question

Monday, October 28, 2013 1:03 PM

Hi All,

Description attribute need to update of bulk user object from TXT file which contains samaccountname.

Kindly suggest PS command

Attirubute value would be - Examine

Thanks

All replies (4)

Monday, October 28, 2013 1:14 PM ✅Answered

Hi,

I'd use Get-Content to read in your input file, a foreach loop to process each user, and Set-ADUser (using the -Replace parameter). Here's the syntax:

http://technet.microsoft.com/en-us/library/ee617215.aspx

http://ss64.com/ps/set-aduser.html

http://ss64.com/ps/get-content.html

http://ss64.com/ps/foreach.html

EDIT: Here's a quick example:

$users = Get-Content .\users.txt

ForEach ( $user in $users ) {

    Set-ADUser $user -Replace @{telephoneNumber='867-5309'}

}

Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,225+ strong and growing)


Monday, October 28, 2013 1:44 PM ✅Answered

Because Set-ADUser's "Identity" parameter accepts pipeline input, you can simplify that example a bit by just piping Get-Content straight to Set-ADUser (I've left the sample -Replace value alone):

Get-Content .\users.txt | Set-ADUser -Replace @{telephoneNumber='867-5309'}

Monday, October 28, 2013 2:19 PM

Because Set-ADUser's "Identity" parameter accepts pipeline input, you can simplify that example a bit by just piping Get-Content straight to Set-ADUser (I've left the sample -Replace value alone):

Get-Content .\users.txt | Set-ADUser -Replace @{telephoneNumber='867-5309'}

Oh yeah, good point. I don't know why, but I always default to using a loop.

Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,225+ strong and growing)


Monday, October 28, 2013 2:32 PM

Oh yeah, good point. I don't know why, but I always default to using a loop.

Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,225+ strong and growing)

Probably because ForEach-Object always works, but other options depend on how the individual cmdlets or functions are written.  :)