
Question:
I need to change the primary group of a user, so I can delete it from it's current one. But my group does not have the attribute "primaryGroupToken", which I need in order to change the primary group of the user. Here is a screenshot of the attribute editor:
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/84rUJ.png" data-original="https://i.stack.imgur.com/84rUJ.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
Obviously, my code responds nothing:
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/wNpWH.png" data-original="https://i.stack.imgur.com/wNpWH.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
Dim domainGroup As New DirectoryEntry("LDAP://our.domain/CN=Domain Users,CN=Users,DC=our,DC=domain")
Dim domainGroupGroupToken As String = domainGroup.Properties("primaryGroupToken").Value.ToString()
Is there a way to manually set it? Or is there something wrong with my code? Thanks in advance.
Answer1:It's a computed property. Stealing from <a href="http://microsoft.public.adsi.general.narkive.com/EtZusqyS/how-get-primarygrouptoken-using-c" rel="nofollow">here</a>, you just need to add a call to <a href="http://msdn.microsoft.com/en-gb/library/913td91k.aspx" rel="nofollow">RefreshCache
</a> before accessing the property:
Dim domainGroup As New DirectoryEntry("LDAP://our.domain/CN=Domain Users,CN=Users,DC=our,DC=domain")
domainGroup.RefreshCache(New String() {"primaryGroupToken"})
Dim domainGroupGroupToken As String = domainGroup.Properties("primaryGroupToken").Value.ToString()
(Not tested, my VB is a bit rusty)