Need help thinking through searching an object

Welcome Forums General PowerShell Q&A Need help thinking through searching an object

Viewing 0 reply threads
  • Author
    Posts
    • #219117
      Participant
      Topics: 3
      Replies: 1
      Points: 13
      Rank: Member

      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)).

      $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"

      or

      $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.

      • This topic was modified 1 month, 1 week ago by tmorrisxyz.
Viewing 0 reply threads
  • You must be logged in to reply to this topic.