Skip to content

Instantly share code, notes, and snippets.

@GodfatherX64
Forked from 9to5IT/Get-ADUserInfo.ps1
Created August 16, 2021 12:52
Show Gist options
  • Save GodfatherX64/d913d48d6995f03c539205ef5023e109 to your computer and use it in GitHub Desktop.
Save GodfatherX64/d913d48d6995f03c539205ef5023e109 to your computer and use it in GitHub Desktop.
PowerShell: Get Active Directory User Information
Import-Module ActiveDirectory
$aResults = @()
$List = Get-Content ".\List.txt"
ForEach($Item in $List){
$Item = $Item.Trim()
$User = Get-ADUser -Filter{displayName -like $Item -and SamAccountName -notlike "admin-*" -and Enabled -eq $True} -Properties SamAccountName, GivenName, Surname, telephoneNumber, mail
$hItemDetails = New-Object -TypeName psobject -Property @{
FullName = $Item
UserName = $User.SamAccountName
Email = $User.mail
Tel = $User.telephoneNumber
}
#Add data to array
$aResults += $hItemDetails
}
$aResults | Export-CSV ".\Results.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment