Hi everyone,
I am trying to compare a .csv which has one column (EmployeeID) with the AD property EmployeeID. This list is an extraction from a certain application where we would like to change from EmployeeID logon to AD Single Sign-on. Therefore we need to get certain data from AD. The current selected fields are:
EmployeeID,Name,EmailAddress,GivenName,Surname,userPrincipalName,SamAccountName
Input file (Example below):
PersonID
999998
999997
123456
789159
753159
258258
I've tried several different approaches but I am missing something.
Example:
Import-Module -Name ActiveDirectory
$ad_users = Get-AdUser -Filter * -Properties EmployeeID, SamAccountName | select EmployeeID, SamAccountName
$users_from_database = Import-Csv "path\userstest.csv" | select PersonID
$ad_employee_numbers = $ad_users | ForEach-Object {$_.PersonID} ## Create an array of strings of only the AD user's employee number
$users_from_database | ForEach-Object {if ($ad_employee_numbers -contains $_.EmployeeID) { $_ }} ## Find all users in the database that are also in Active Directory
Anyone who can shed some light on where I'm making the mistake?