PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,455 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
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"
}
}