{"id":58,"date":"2015-05-04T01:32:00","date_gmt":"2015-05-04T01:32:00","guid":{"rendered":"http:\/\/geekmungus.co.uk\/?p=58"},"modified":"2022-11-05T10:53:19","modified_gmt":"2022-11-05T10:53:19","slug":"set-a-specific-ad-attribute-with-powershell","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=58","title":{"rendered":"Set a specific AD attribute with PowerShell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">So here is an example you want to set all the users in the OU called &#8220;Users&#8221; to have the extensionAttribute10 with the value &#8220;student&#8221; to do this you can run the below script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$users = Get-ADUser -Filter * -SearchScope Subtree -SearchBase \"OU=Users,DC=domain,DC=co,DC=uk\" | Select-Object DistinguishedName, SamAccountName\n\nforeach ($i in $users)\n\n{\n\n$id = $i.DistinguishedName\n\n$extattrib2 = Get-ADUser -Identity $id -Properties extensionAttribute10 | select-object -ExpandProperty extensionAttribute10\n\nWrite-Host $i.SamAccountName,\"-\",$extattrib2\n\nSet-ADUser -Identity $i.SamAccountName -Add @{extensionAttribute10 = \"Student\"}\n\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So here is an example you want to set all the users in the OU called &#8220;Users&#8221; to have the extensionAttribute10 with the value &#8220;student&#8221; to do this you can run the below script:<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,14],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-microsoft-windows"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":1441,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/1441"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}