Skip to content

Instantly share code, notes, and snippets.

@9to5IT
Last active December 24, 2022 02:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 9to5IT/d0f54aaa78d94673ff73 to your computer and use it in GitHub Desktop.
Save 9to5IT/d0f54aaa78d94673ff73 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