54027

AD: Group does not have a primaryGroupToken attribute

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)

Recommend

  • How to programmatically set App Pool Identity
  • List of email address to public folders in exchange
  • Does anyone know exactly what javax.jms.InvalidDestinationException: Not allowed to create destinati
  • Sql Copy table from One Database to Another Database
  • Creating certificate using makecert without pvk file
  • OpenLDAP sAMAccountName as custom attribute
  • Detect the cell phone connected to wireless network - C#
  • Allow anonymous access to parts of a secured Subversion repository
  • Pending Intent triggered by Alarm Manager seems to fire right away
  • Can't I use JQuery inside my FancyZoom popup?
  • How do you connect to an LDAP server using node-oracledb?
  • add an element to a node, if it doesnot exist
  • Can I redirect to a valid Wicket page when attempting to access a non-existent page?
  • Spring Security 3.1.3 @EnableWebSecurity
  • Finding what Groups/Distribution lists a specific user belongs to in active directory
  • How to add plugin dependencies to pom.xml
  • Giving security priviliege to a scheduler in Java EE 6
  • How do I embed a custom user-control in MS Word?
  • Reload UITableView from another tab
  • gulp.watch running same task multiple times when saving many files
  • Accessing Windows Azure Queues from client side javascript/jquery
  • Weighted round robin dns between 2 Cloudfront distributions
  • proxy request in node.js / express
  • PHP Copy function not working
  • Firefox augments the content-type of XMLHttpRequest
  • CKeditor stripping font tags instead of converting to span
  • How can I add div content to a new page in jspdf?
  • Double-click autofill - dynamic based on adjacent cell
  • Excel VBA URLDownloadToFile Error for https Ressource
  • Creating a Multidimensional, Associative Array in VBScript
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • Conversion from string “a” to type 'Boolean' is not valid
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Email verification using google app script and google forms
  • Acquiring multiple attributes from .xml file in c#
  • How do you join a server to an Active Directory (domain)?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal