Hello there,
To add or update user attribute values for Active Directory users, you can use PowerShell along with the Set-ADUser cmdlet. Before running the script, ensure that you have the necessary permissions to modify user attributes in the Active Directory.
Here's an example PowerShell script that demonstrates how to add or update user attribute values:
Import the Active Directory module
Import-Module ActiveDirectory
Replace these values with your domain-specific information
$Username = "JohnDoe" # The username of the user you want to update
$AttributeName = "extensionAttribute1" # The name of the attribute you want to add/update
$AttributeValue = "New Value" # The value you want to set for the attribute
Get the user object from Active Directory
$user = Get-ADUser -Identity $Username
Check if the user exists
if ($user) {
# Check if the attribute already has a value
if ($user.$AttributeName) {
# If the attribute already has a value, update it
Set-ADUser -Identity $Username -Add @{ $AttributeName = $AttributeValue }
Write-Host "Attribute '$AttributeName' updated for user '$Username' with value: '$AttributeValue'"
} else {
# If the attribute doesn't have a value, add it
Set-ADUser -Identity $Username -Replace @{ $AttributeName = $AttributeValue }
Write-Host "Attribute '$AttributeName' added for user '$Username' with value: '$AttributeValue'"
}
} else {
Write-Host "User '$Username' not found in Active Directory."
}
Replace the placeholders (JohnDoe, extensionAttribute1, New Value, etc.) with your actual values. The script checks if the specified attribute exists for the user. If it does, it updates the value; otherwise, it adds the attribute with the given value.
Save this script with a .ps1 extension and run it with administrative privileges on a machine that has the Active Directory PowerShell module installed. The script should modify the specified user's attribute values accordingly.
I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–