Powershell Script to Get List of Active Users with the Details like samaccountname, name, department, job tittle, email in Active Directory

 

In this blog will see how to list active users with details like samaccountname, name, department, job tittle, email, etc., in Active Directory using powershell script.

  

A dsquery solution:

dsquery * -Filter "(&(objectCategory=person)(objectClass=user))" -Attr givenName sn displayName sAMAccountName mail proxyAddresses distinguishedName > AllUsers.txt

 

A PowerShell solution using the AD module cmdlet:

Get-ADUser -Filter * -Properties givenName, sn, displayName, sAMAccountName, mail, proxyAddresses, distinguishedName | ft givenName, sn, displayName, sAMAccountName, mail, proxyAddresses, distinguishedName > .\AllUsers.txt

 

Script for logon name, First name and Last name for all Active Directory users in a specified OU. 

$params = @{  "Filter" = "*"  "SearchBase" = "OU=Users,DC=fabrikam,DC=com"}Get-ADUser @params |  Select-Object Surname,GivenName,SamAccountName |  Export-Csv "MyOutputFile.csv" –NoTypeInformation