In this blog post, I will discuss with you how to get ad users properties from a 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 IDs in csv file. Based on employee ID, you want to get active directory user 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, the Import-CSV command imports ad users from csv file and passes 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 the $UserAttributesList variable.
In the final step, using the Export-Csv cmdlet in PowerShell, it exports the ad user to csv file AdUserAttributes.csv. The 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 the Get-ADUser cmdlet!
Conclusion
With using PowerShell Get-ADUser cmdlet, you can easily get aduser attributes filtered by specific property from csv file and export aduser attribute information to csv file again.
Cool Tip: Read more about Get-ADUser using userprincipalname or upn in PowerShell!