Google Reviews
If you find this content or our services useful, please leave us a review.

Other Posts in this Series:

This post provides an example of how we can use ADSI to set and clear Active Directory Attributes.  We search for a user called “alkaneuser” and set or clear the department attribute.

$objSearcher=[adsisearcher]'(&(objectCategory=person)(objectClass=user)(sAMAccountName=alkaneuser))'
	
$colProplist = "samaccountname","department"
foreach ($i in $colPropList) { $objSearcher.PropertiesToLoad.Add($i) | out-null } 
	
$colResults = $objSearcher.FindOne()	
 
if ($colResults -ne $null)
{   	  
    $user = [adsi]($colResults.Properties).adspath[0]

    #set attribute
    $user.Put("department", "Example department2"); 
    $user.setinfo();
        
    #clear attribute - uncomment as required
    #$user.PutEx(1, "department", 0); 
    #$user.setinfo();   	
}
Use ADSI to Set and Clear Active Directory Attributes
Comments have now been disabled. If you have a question to ask about this post please ask the community!