Hello All,
Its been some time that I wrote an article, but today we will seeing how to change AD user description field in Active Directory.
Of course we will be using Powershell to perform this. But be aware that we can do this from Active Directory Users and Computers as well.
Let us say that we have a user Ronnie and the description provided for the user is "Ronnie is from the Marketing Team"
You can see the below from the Active Directory Users and Computers.
Let us say that you want to change that to "Marketing Department User"
We would use a cmdlet called Set-ADUser to perform this action.
This is actually one of the cmdlets which has the ability to modify the largest number of attributes related to a user account in Active Directory.
So the command that will change the description is
Set-ADUser Ronnie -Description "Marketing Department User"
Yes it was as simple as that.
Now this doesn't make sense for a single account to do this from a Powershell window. You are better off using the Active Directory Users and Computers.
But imagine, you as an Administrator receive request to change 500 user descriptions and your manager just sent that in an excel sheet.
That is when Powershell comes into the picture to make your life simple.
Let us say that you modified the excel file that you received and converted to csv file in the below format.
The first column contains the SamAccountName and the second column you can have the updated description that needs to be applied.
So the way you would write the script will be as seen below.
Import-Module ActiveDirectory
$Users = Import-csv c:\Users.csv
foreach($User in $Users){
Set-ADUser $User.SamAccountName -Description $User.NewDescription
}
Save it as a .ps1 file and run from a Powershell window.
Boom! You just updated 500 User accounts details that easily.
I hope that this was informative and thank you for reading!
7 Comments
Helpful Script Options
Import-Module ActiveDirectory
$Users = Import-csv c:\test\test.csv
foreach($User in $Users){
Set-ADUser $User.SamAccountName -Description $User.Description
}
WAY THIS NOT WORKING
The script has a mis-spelling
The .csv file has the names under SaAccountName
The script is calling for SamAccountName
Change one to match the other and it should work just fine.
Another issue is your script says this:
Import-Module ActiveDirectory
$Users = Import-csv c:\test\test.csv
foreach($User in $Users){
Set-ADUser $User.SamAccountName -Description $User.Description
}
Your Error is also here (Yours still says $Users, but this points tot he document and your Doc is test: not Users.) See Below:
foreach($User in $test){
Also (Depending on your CSV file, the heading for the column maybe wrong. If it was typed in your CSV as “Description” and not “NewDescription” then it is correct, but if it is the reverse then yours is incorrect) See example CSV in the above help blog.
Set-ADUser $User.SamAccountName -Description $User.Description
}
Many many thanks!!!
I will try this out for sure- this is the first time I have worked a powershell command with a csv.
thanks guys
Hey there! Would you mind if I share your blog with my
twitter group? There’sa lot of folks that I think would really appreciate your content.
Pleaae let me know. Cheers