Getting a specific attribute about each AD User using PowerShell

Active Directory Microsoft Windows

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
}