Welcome › Forums › General PowerShell Q&A › Need help thinking through searching an object
I’m writing a script to automate the validation of Active Directory accounts with an HR spreadsheet of current employees.
Active Directory accounts have an employee number in the EmployeeID field.
I can create a typical object of employees.
$Users = Get-ADUser -Filter * -Properties employeeid | Where-Object EmployeeID -ne $null | Where-Object Enabled -eq "True" | Select-Object EmployeeID,SamAccountName,Givenname,Surname | Sort-Object surname,givenname
I can run this through a loop (ForEach ($User in $Users)).
ForEach ($User in $Users)
$User.EmployeeID accurately returns the employee number (e.g. 0054321).
I can create an object from the HR spreadsheet that contains all the employees.
$CurrentEmployees = Import-Excel -Path "C:\path\file.xlsx"
$CurrentEmployees = Import-Csv -Path "C:\path\file.xlsx"
Employee Number is the column that I want to check against.
My question is, what do I run in my ForEach to check if a value in $User.EmployeeID is found (or more importantly, not found) in $CurrentEmployees (in the Employee Number column).
I would then export two different reports (found, not found).
Thanks in advance for your consideration.