Gakki
Gakki

Reputation: 23

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
}

Upvotes: 0

Views: 1428

Answers (1)

Guy S
Guy S

Reputation: 472

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

Upvotes: 1

Related Questions