Powershell script to modify custom user attributes in Active Directory

There are a lot of blogs on the web that suggest you use Quest’s AD powershell commands like Set-QADUser to modify custom user properties. But what if you don’t have Quest?
I wrote a short script that modifies a custom attribute without the use of Quests tools. The script uses a command called Set-ADObject. This command can be used to modify any AD object – users, computers and etc… so you can very easily modify my script the change custom properties for a computer object.
The script imports a list of users (sAMAccountNames) from a CSV file and adds a certain value to a certain property for each user.
Here’s the script:
# The value of the property
$Value = 'Some Value here'

# The property
$Property = @{CustomProperty1=$Value}

# Importing the users that going to be Tagged - sAMAccountNames
$Users = Import-CSV Users.CSV

# For each user add the above value to the above propery
foreach ($usr in $Users)
{
$sAMAccountName = $usr.samaccountname
Write-host -NoNewLine "Modifying $sAMAccountName Properties...."
Get-ADObject -Filter 'samaccountname -eq $sAMAccountName' | Set-ADObject -add $Property
Write-host "Done!
}

Incoming search terms:

  • powershell script to modify custom user attributes in active directory
  • PowerShell Update Custom attribute User
  • active directory powershell arbitrary attributes
  • powershell mail attribute csv
  • powershell modifying active directory attributes
  • powershell set ad object attributes
  • powershell set custom ad attribute
  • powershell set custom attributes
  • Quest powershell to update account attribute
  • script to set adobject attribute

7 Comments

  1. I’m not that much of a internet reader to be honest but your blogs really nice,
    keep it up! I’ll go ahead and bookmark your site to come back in the future. All the best

    • Hi,
      Thx a a lot!
      I know that for some reason my RSS link is’nt working (it does on Firefox), but Ill fix it soon!
      Let me know what interests you more…

  2. Cheers ! my friend , thank u very much ! 🙂
    it’s very assist my 2 resolve my issue! 🙂

  3. Sorry, powershell noob here. How does this script actually connect to the correct AD server?

    • Hi Victor,
      Feel free to ask anything!

      This script uses cmdlets that are part of the ActiveDirectory module. You will have to install it locally on the computer you’re running the script from.
      In case you’re running the script on the Domain Controller then it should work automatically.

      Let me know how it works for you!

    • Hi Ramesh, thx for your link.
      I’m not familiar with this tool you’ve linked but it appears that it costs money. I use many tools in my daily work, some of them cost money and some don’t. I agree that using tools is much easier and simpler than scripts for some of the work but the versatility and capabilities of scripts, and powershell especially, cannot be argued.

      If you wan’t, I will be more than happy to give you example of the scripts I use.

Leave a Reply to Ramesh Cancel reply