Last active
December 24, 2022 02:20
-
-
Save 9to5IT/d0f54aaa78d94673ff73 to your computer and use it in GitHub Desktop.
PowerShell: Get Active Directory User Information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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