I'm trying to edit a bulk of users that I have their samaccountname in a CSV. The attrib that I need to update is EmployeeID
I have zero coding skill
my CSV file looks like this
logon;EmployeeID
User1@company.local;12345678
validate whether or not the employeeid attribute is set and then only set it if it's blank otherwise skip it.
i found some code from google but it is not working
$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 "c:\UserList-Results.csv"
Any tips ? thanks !!