Getting a specific attribute about each AD User using PowerShell

posted 14 May 2015, 06:16 by Tristan Self
Using powershell you can get the value of a specific attribute of a user. To do this run the below, this will get all the user objects in the OU called "Users" and display the samAccountName and extensionAttribute10 attribute.

$users = Get-ADUser -Filter * -SearchScope Subtree -SearchBase "OU=Users,DC=domain,DC=co,DC=uk" | Select-Object DistinguishedName, SamAccountName

foreach ($i in $users)
{
$id = $i.DistinguishedName
$extattrib2 = Get-ADUser -Identity $id -Properties extensionAttribute10 | select-object -ExpandProperty extensionAttribute10
Write-Host $i.SamAccountName,"-",$extattrib2
}

Comments