Set a specific AD attribute with PowerShell

Active Directory Microsoft Windows

So here is an example you want to set all the users in the OU called “Users” to have the extensionAttribute10 with the value “student” to do this you can run the below script:

$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

Set-ADUser -Identity $i.SamAccountName -Add @{extensionAttribute10 = "Student"}