I got all the right values from my csv. And when I try to write the "Get-ADUser | Set-ADUser" manually everything works like it should. Does anybody see, what am I missing here?
You state “everything works like it should”. I take it that it is not working. Do you get an error?
I would look at creating a hashtable and using it to make the changes.
The are many articles and pre-built script that you can use as is or tweak as needed for your use case. No reason to start from scratch, unless of course this is a homework assignment or general edification effort. Even in the latter case, learning from others work is paramount for clarity of direction, even if you later come up with a better option / solution.
Update Active Directory Users in Bulk from CSV
PowerShell V2 script to update Active Directory users from a CSV file. Only specified fields in the CSV that are not missing update the users. The value “<delete>” flags to clear the attribute. Attributes are not updated if the value in the CSV matches the existing value in AD.
Update Active Directory User attributes from CSV
This script will feed data from CSV file to Active directory user attributes.I have included two scripts one will overwrite the existing data & other will only write if existing attributes are blank.Prerequisites:- quest management tools should be installed.CSV format:- This is a
If all your values are already in the file, then just use those directly. No real need for the Get-ADUser.
It could as simple as doing something link this (splatting being used just for better readability)…
$Users = Import-CSV c:\script\userattributes.csv
foreach ($User in $Users)
{
$ADUserParams = @{
displayName = $User.displayname
department = $User.department
title = $User.title
l = $User.l
StreetAddress = $User.streetaddress
st = $User.st
}
Set-ADUser @ADUserParams
}