'Update EmployeeID Attribute based on csv
Here is the code I used to update the employeeID attribute based on csv. I want to do verify the input value and then return the result of not matching items. Any suggestions? Thanks!
Import-module ActiveDirectory
Import-CSV “C:\PSS\UserList.csv” | % {
$mail = $_.mail
$ID = $_.EmployeeID
$users = Get-ADUser -Filter {mail -eq $mail}
Set-ADUser $Users.samaccountname -employeeID $ID
}
Solution 1:[1]
No sense over-complicating it.
Import-module ActiveDirectory
$failedAccounts = @()
Import-CSV “C:\PSS\UserList.csv” | % {
$mail = $_.mail
$ID = $_.EmployeeID
$users = Get-ADUser -Filter {mail -eq $mail}
if ($users -ne $null){
Set-ADUser $Users.samaccountname -employeeID $ID
}
else {
$failedAccounts += $mail
}
}
Write-Host "Failed Accounts: $($failedAccounts.count)"
$failedAccounts
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Guy S |
