{"id":682,"date":"2012-01-10T10:51:58","date_gmt":"2012-01-10T08:51:58","guid":{"rendered":"http:\/\/hen.co.za\/blog\/?p=682"},"modified":"2012-01-10T21:08:42","modified_gmt":"2012-01-10T19:08:42","slug":"adding-an-user-to-group-in-ad","status":"publish","type":"post","link":"https:\/\/hen.co.za\/blog\/2012\/01\/adding-an-user-to-group-in-ad\/","title":{"rendered":"Adding an user to group in AD"},"content":{"rendered":"<p>I was helping a colleague that has no programming background with a little tool he needs to create to add users to an AD group. The &#8216;tricky&#8217; part is that he started using VB (.net) and my VB skills is a bit (or a lot) rusty&#8230;<\/p>\n<p>So I set out to help him but I hit a little snag with the step of actually adding a user to the group.\u00a0 I got an exception &#8216;<span style=\"color: #800000;\"><em>The server is unwilling to process the request<\/em><\/span>&#8216; when trying to use the following type of code:<\/p>\n<blockquote>\n<div>de = <span style=\"color: #0000ff;\">new DirectoryEntry<\/span>(groupDn);<\/div>\n<div>de.Properties[&#8220;member&#8221;].<strong>Add<\/strong>(userDn); <span style=\"color: #008000;\">\/\/&lt;!&#8211; breaks here<\/span><\/div>\n<div>de.CommitChanges();<\/div>\n<\/blockquote>\n<div>I suspected a security issue but even running this code under raised privileges (admin) does not help. The solution is to rather call the COM add method directly:<\/div>\n<div><\/div>\n<blockquote>\n<div>de = <span style=\"color: #0000ff;\">new DirectoryEntry<\/span>(groupDn);<\/div>\n<div>de.Invoke(&#8220;Add&#8221;, New Object() {userDn})<\/div>\n<\/blockquote>\n<div>Note: groupDn and userDn must be the full LDAP path to the group and user objects.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I was helping a colleague that has no programming background with a little tool he needs to create to add users to an AD group. The &#8216;tricky&#8217; part is that he started using VB (.net) and my VB skills is &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/hen.co.za\/blog\/2012\/01\/adding-an-user-to-group-in-ad\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7,9,303],"class_list":["post-682","post","type-post","status-publish","format-standard","hentry","category-development","tag-net","tag-code","tag-development"],"_links":{"self":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/comments?post=682"}],"version-history":[{"count":3,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/682\/revisions"}],"predecessor-version":[{"id":684,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/682\/revisions\/684"}],"wp:attachment":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/media?parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/categories?post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/tags?post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}