Reputation: 21
I have a source CSV file with multiple columns, and I want to update some but not all of those columns into the matching user in AD.
# Import AD Module
Import-Module ActiveDirectory
# Import CSV into variable $userscsv
#$userscsv = import-csv
$users = Import-Csv -Path 'C:\Scripts\ADUPLOADtest2.csv'
# Loop through CSV and update users if the exist in CSV file
foreach ($user in $users)
{
#Search in specified OU and Update existing attributes
Get-ADUser -Filter "SamAccountName -eq '$($user.Username)'" -Properties * |
Set-ADUser -employeeNumber $($user.Emp_Code) -extensionAttribute4 $($user.Cost_Centre) -title $($user.Role) -Department $($user.Work_Area)
}
Source CSV file example:
Emp Code,Username,Surname,Manager,First name,Department,Division,Section,Team,Role,Work Area,Cost Centre
82644,aah,Haven,Peter Jones,April,Executive,Community Wellbeing,General,General,Community Wellbeing Support Officer,Community Wellbeing,50016001
Using the code above with the example CSV, I am currently getting the error below on the extensionAttribute4 field update:
Any advice would be greatly appreciated.
Upvotes: 2
Views: 4904
Reputation: 34
As the error says, the parameter does not exist. have you tried something like - Set-ADUser -Add @{attributename="TheRequiredValue"}
Upvotes: 1