I have a CSV file that I need to bulk update AD with. The file has an employeeID, which would match the employeeID field in AD. So far, I've been able to update a user successfully with a CSV file if there is just one row of information. What changes would I need to make to my script to allow for many users/rows to be updated?
$Path = "C:\import\users-test.csv "
$users = Get-Content –Path $Path | ConvertFrom-CSV
$users | foreach {
$_.psobject.properties | foreach { if ($_.value -eq "") { $_.value = $null }}
$eid = $_.empID
$user = Get-ADUser -Filter {employeeID -eq $eid}
Set-ADUser $user.samaccountname -title $_.Title –department $_.department –description $_.Description –office $_.Office –streetAddress $_.Street –city $_.City –postalCode $_.Zip –state $_.State –OfficePhone $_.Telephone –Country $_.Country –add @{extensionattribute11=$_.License}
}
EDIT: Updated code based on feedback. still isn't working.
Any help would be appreciated. This would be something that would be ran on a semi regular basis.
Thanks,
Jim
UPDATE: The error I'm getting is this -
Set-ADUser : Cannot validate argument on parameter 'Add'. The argument is null or an element of the argument collection contains a null value. At line:7 char:250
+ ... _.Country –add @{extensionattribute11=$_.License}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADUser