TechKnow

Author Topic: [PS] List Active Directory Users with active e-mail addresses  (Read 359 times)

0 Members and 1 Guest are viewing this topic.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9936
  • Karma: +2284/-111
[PS] List Active Directory Users with active e-mail addresses
« on: February 27, 2018, 01:12:16 PM »
List Active Directory Users with active e-mail addresses

Description: A simple, small powershell script to create a list of users with their active e-mailaddresses
Example: listuae.ps1 "fourthlevel OU"
NOTE: Replace the BOLD pieces in the code confirm your AD

listuae.ps1

param($afd)

$ou = "OU=$afd,OU=%THIRDLEVEL%,OU=%SECONDLEVEL%,OU=%FIRSTLEVEL,(DOMAIN)%,DC=%COMPANYNAME%,DC=local"

"`nMicrosoft"
Get-ADUser -ResultSetSize 3000 -SearchBase $ou -SearchScope SubTree -Properties mail,Enabled -Filter {(mail -like '*') -and (Enabled -eq 'True')} | Format-List Name, DistinguishedName, mail, Enabled

"`nActive Mailboxes"

$root = [ADSI]"LDAP://$ou"
$search = [adsisearcher]$root
$search.Filter = "(&(objectclass=user)(objectcategory=user))"
$search.SizeLimit = 3000
$results = $search.FindAll()

foreach ($result in $results){
    $result.Properties |
    select @{N="Name"; E={$_.name}}, @{N="Email"; E={$_.mail}}
}
« Last Edit: March 01, 2018, 11:56:38 AM by Stephan »