Set a specific AD attribute with PowerShell

posted 14 May 2015, 06:32 by Tristan Self
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"}
}


Comments