I have a csv file with people data. One row per person. I want to update Active Directory with the data using powershell, but only the first row is updated in Active Directory.
How can I modify the code to update all the row values?
Import-Module ActiveDirectory
Import-Csv "C:\code.csv" -Delimiter ';' -Encoding "UTF8" |
ForEach-Object
{
$params = @{Identity = $_.SamAccountName}
if (-not [string]::IsNullOrWhiteSpace($_.Surname))
{
$params.Surname = $_.Surname
}
if (-not [string]::IsNullOrWhiteSpace($_.Givenname))
{
$params.Givenname = $_.Givenname
}
if (-not [string]::IsNullOrWhiteSpace($_.DisplayName))
{
$params.DisplayName = $_.DisplayName
}
if (-not [string]::IsNullOrWhiteSpace($_.Title))
{
$params.Title = $_.Title
}
if (-not [string]::IsNullOrWhiteSpace($_.Department))
{
$params.Department = $_.Department
}
if (-not [string]::IsNullOrWhiteSpace($_.Manager))
{
$params.Manager = $_.Manager
}
if (-not [string]::IsNullOrWhiteSpace($_.OfficePhone))
{
$params.OfficePhone = $_.OfficePhone
}
if (-not [string]::IsNullOrWhiteSpace($_.MobilePhone))
{
$params.MobilePhone = $_.MobilePhone
}
}
Set-ADUser @params
The csv file:
SamAccountName;surname;givenname;displayname;Job Title;Department;Manager;HomePhone;MobilePhone test1;Test;1;Test 1;;;;; test2;Test;2;Test 2;something;anything;test1;136 / 8022;-1079