Here is the code I used to update the employeeID attribute based on csv
$Users = Import-CSV "C:\PSS\UserList.csv"
$Results = $Users | ForEach-Object {
try {
$User = Get-ADUser -Filter {mail -eq $_.mail}
if ($null -ne $User -and $null -eq $_.EmployeeID) {
try {
Set-ADUser $User.SamAccountName -EmployeeID $_.EmployeeID
$_ | Add-Member -MemberType NoteProperty Status -Value "Complete"
} catch {
$ErrorMessage = $_.Exception.Message
$_ | Add-Member -MemberType NoteProperty Status -Value $ErrorMessage
}
} else {
$_ | Add-Member -MemberType NoteProperty Status -Value "Skipped"
}
} catch {
$ErrorMessage = $_.Exception.Message
$_ | Add-Member -MemberType NoteProperty Status -Value $ErrorMessage
}
}
$Failed = $Results | Where-Object {$_.Status -ne "Complete" -and $_.Status -ne "Skipped"}
Write-Host "Failed Accounts: $($Failed.Count)"
$Results | Export-Csv -Path "UserList-Results.csv"
Here is my excel file
I ran this code but the output in csv is empty and employeeid attribute does not change. Any suggestions?