Powershell Script - Employee still in company using excel sheet

mrsolo 0 Reputation points
2023-03-28T15:34:37.8633333+00:00

We have a list of users email address in excel sheet. I'm trying to find a way to use excel sheet as source and find if the user is an active employee in the company using Active Directory.

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,455 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,551 Reputation points
    2023-03-28T18:56:57.2133333+00:00

    If you're going to work with Excel files, do yourself a favor and install the ImportExcel module (https://www.powershellgallery.com/packages/ImportExcel/7.0.1). You'll save yourself a lot of time and effort by not having to deal with the Excel application COM object.

    Import-Excel -Path C:\junk\addr.xlsx |
        ForEach-Object{
            $e = Get-ADUser -Filter {emailaddress -eq $_.addr} -properties emailaddress
            $status = "DISABLED"
            if ($e){
                if ($e.Enabled){
                    $status = "ENABLED"
                }
                Write-Host "$($e.emailaddress) is a(n) $status employee"
            }
            else{
                Write-Host "$($e.emailaddress) is NOT an employee"
            }
        }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.