Hi,
Please don't post your code as an image. You just need to test if the AD user exists
Import-Csv C:\Temp\EMPID.csv | ForEach-Object {
$user = Get-ADUser -Filter "EmployeeID -eq $($_.EmployeeID)"
$user | Select-Object Name, SamAccountName, UserPrincipalName
if(-not $user){
$_ |Export-Csv C:\temp\EmpIDnotfound.csv -Encoding UTF8 -NoTypeInformation -Append
}
} | Export-Csv C:\temp\EmpIDresults.csv -Encoding UTF8 -NoTypeInformation
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.