I need to update all below mentioned AD attributes from a CSV file, please let me know if i can update these in one script or do i need multiple scripts? Please help me with detailed steps, i am not so good in scripting. Thanks.
CSV file have filled:
Samaccountname,emailaddress,officephone,manager,Title,EmployeeID,Office,Department,Company
emailaddress
officephone
manager
Title
EmployeeID
Office
Department
Company
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications. PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,510 questions Sign in to follow 7 comments Hide comments for this question Report a concern I have the same question I have the same question 0Not working for me. I am getting these error messages at the bottom. Import-Csv -Path "C:\temp\adinfo.csv" |
ForEach-Object < # properties from the csv $acct = $SamAccountName # needed for error message $props = @< officephone = $_.officephone employeetype = $_.employeeType >Try < Get-ADUser -Identity $_.SamAccountName -Properties * -ErrorAction STOP| Set-ADUser @props -ErrorAction STOP >Catch < Write-Host "User '$acct' not found or failed to update: " Write-Host $_ >>
User '' not found or failed to update: A parameter cannot be found that matches parameter name 'employeetype'.
0 votes Report a concern Rich Matheisen 46,556 Reputation points 2024-03-07T19:03:10+00:00Well, that's understandable. The Set-ADUser cmdlet doesn't have a parameter named "EmployeeType". Try doing it like this:
Import-Csv -Path "C:\temp\adinfo.csv" | ForEach-Object < # properties from the csv $acct = $_.SamAccountName # needed for error message Try < Set-ADUser -Identity $_.SamAccountName -OfficePhone $_.officephone -Replace @-ErrorAction STOP > Catch < Write-Host "User '$acct' not found or failed to update: " Write-Host $_ >>
Edit: Added missing "$." in $acct = $SamAccountName , removed the unnecessary hash of parameter names and values (replaced by available parameters in Set-ADUser), and removed unnecessary Get-ADUser. Replaced "Type" in -Replace by "employeetype".
0 votes Report a concern Kehring, Tim 0 Reputation points 2024-03-07T20:00:05.81+00:00Thanks for the reply. I ran that script exactly as you showed and still getting these errors. User '' not found or failed to update: Cannot bind parameter 'Replace'. Cannot convert the "@
My bad. The $_.Type was supposed to be $_.employeetype . I omitted the "employee" part. :-( The code has, again, been corrected. Not having an AD to work with makes it hard to discover typos!
0 votes Report a concern Kehring, Tim 0 Reputation points 2024-03-08T13:41:20.63+00:00Thanks so much Rich, that worked. What is the difference between the Office Phone attribute and the EmployeeType attribute that the script is different? If I want to add more attributes, not sure I would know how to add them.
0 votes Report a concern Rich Matheisen 46,556 Reputation points 2024-03-08T16:19:22.2566667+00:00If the modifications use a different set of properties on different users it usually better to use splatting (i.e., a hash table). Build the parameter name/values for each user from scratch. This is easy to accomplish if the properties you're modifying are represented by existing parameters on the Set-ADUser cmdlet. For modifications/additions/removals/etc. to properties not represented by existing parameter names you'll have to construct the necessary scriptblocks, which is not quite as easy (but still "doable"). Whether you add that stuff to the hash or not depends on you level of comfort and willingness to experiment a bit. :-)
1 vote Report a concern Show 2 more comments Add comment Accepted answer Rich Matheisen 46,556 Reputation points 2022-05-08T02:03:58.807+00:00You could continue adding the individual parameters and values to the Set-ADUser cmdlet, making it longer and more cumbersome to deal with, of you could use a hash to assemble the parameters and values and use "splatting" to keep the clutter down. I also added some minimal error handling.
Import-Csv -Path "C:\temp\adinfo.csv" | ForEach-Object < # properties from the csv $acct = $_.samaccountname # needed for error message $props = @< EmployeeID = $_.EmployeeID Office = $_.Office title = $_.title Department = $_.Department emailaddress = $_.emailaddress officephone = $_.officephone manager = $_.manager company = $_.company >Try < Get-ADUser -Identity $_.SamAccountName -Properties * -ErrorAction STOP| Set-ADUser @props -ErrorAction STOP >Catch < Write-Host "User '$acct' not found or failed to update: " Write-Host $_ >>
EDIT: Added $ Thanks for the command, it worked for me. I need to set description same as job title, could you please add into this command
0 votes Report a concern Rich Matheisen 46,556 Reputation points 2022-05-09T21:23:36.31+00:00 Just replace line 14 (it's empty) with:description = $_.title
I think you should also download this free PDF: Windows-PowerShell-4 Read the 1st half of the book and do the exercises. When you feel confident, read the 2nd half of the book which demonstrates using PowerShell to perform common administrative tasks. The 2nd half uses what you learned in the 1st half.
0 votes Report a concern Naveen Kumar 21 Reputation points 2022-05-09T21:27:39.273+00:00 Thanks for your quick response and valuable help. 0 votes Report a concern Add commentEvery one of those attributes have a corresponding parameter on the Set-ADUser cmdlet. You can do what you need in a few lines of code.
1 comment Show comments for this answer Report a concern Naveen Kumar 21 Reputation points 2022-05-08T00:20:50.073+00:00I have a CSV file (c:\temp\adinfo.csv) with fields:
Samaccountname,emailaddress,officephone,manager,Title,EmployeeID,Office,Department,Company Import-Module ActiveDirectory
Import-CSV -Path "C:\temp\adinfo.csv" | Foreach-Object
$SamAccountName = $.SamAccountName
$EmployeeID = $.EmployeeID
$Office = $.Office
$title = $.title
$Department = $_.Department
$SamAccountName
$EmployeeID
$Office
$title
$Department
Get-ADUser -Filter "SamAccountName -eq '$SamAccountName'" -Properties * | Set-ADUser -Title $title -EmployeeID $EmployeeID -Office $Office -Department $Department
> I have this command which works for me to update only 4 attributes (Title,EmployeeID,Office,Department)
Could you please let me know what I need to add into above command to update emailaddress,officephone,manager, company attributes as well.

Hi @Naveen Kumar , for the Set-AdUser command you will find the parameters and examples here: https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps Here you will find some examples how to work with Set-AdUser and how to update multiple users using a csv file: https://lazyadmin.nl/powershell/set-aduser/ If you started with your script and need some more help please ask and post your script (using the CodeSample option of the Q&A editor for the script (the icon with 101010)) together with the error message or details what isn't working properly. ---------- (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you) Regards
Andreas Baumgarten
Getting below error while running the script.. User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: replace User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: replace User '' not found or failed to update: replace User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: replace User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: replace User '' not found or failed to update: replace User '' not found or failed to update: replace User '' not found or failed to update: replace User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: replace User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: replace User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object User '' not found or failed to update: The requested operation did not satisfy one or more constraints associated with the class of the object ========================================================= Not a single attribute updated.
0 votes Report a concern Rich Matheisen 46,556 Reputation points 2023-08-22T14:49:54.3666667+00:00You shouldn't be adding to an already answered question, especially after more than a year since the answer was accepted. What you should do is to create your own question and with it supply enough information to document your problem. So, where's the script you used? What are the column names in the CSV? What types of values are in the CSV columns? A CSV can only contain text, not complex objects like lists or hashes. The error "The requested operation did not satisfy one or more constraints associated with the class of the object" implies you're trying to put a value into a user property that is not allowed by the schema definition of the attribute.