Home » PowerShell » Get-ADUser attributes from CSV list of users in PowerShell

Get-ADUser attributes from CSV list of users in PowerShell

In this blog post, I will discuss with you about how to get ad users properties from csv file. We will be using PowerShell Get-AdUser cmdlet and filter parameter to get active directory user information, get aduser attributes or PowerShell get user properties and export ad users to csv file.

Let’s consider you have a list of aduser employee id in csv file. Based on employee id, you want to get active directory users attributes or get-aduser all properties and export ad users to csv.

$UserAttributesList = @()

#  Iterate over list to get ad user attributes filter by employee id and store result
Import-CSV D:\PowerShell\AdUsers.csv | ForEach-Object { 
$UserAttributesList  += Get-ADUser  -Filter "employeeid -eq $($_.employeeid)" -Properties SamAccountName, Name, Mail| select samaccountname, name, mail
}

In the above PowerShell script, it import ad users from csv file using Import-CSV and pass through to ForEach-Object for iteration to get ad user filter by employee id and get ad user attributes like SamAccountName , Name and Mail attributes.

It stores aduser attributes in $UserAttributesList variable.

In the final step, using Export-Csv cmdlet in PowerShell ,it export ad user to csv file AdUserAttributes.csv. Csv file contains ad user all properties.

$UserAttributesList   | Export-csv D:\Powershell\AdUserAttributes.csv -Append -NoTypeInformation

Cool Tip: Read more about 10 real world examples using Get-ADUser cmdlet !

Conclusion

With using PowerShell Get-ADUser cmdlet, you can easily get aduser attributes filter by specific property from csv file and export aduser attributes information to csv file again.

Cool Tip: Read more about Get-ADUser using userprincipalname or upn in PowerShell!

Leave a Comment