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:

enter image description here

Obviously, my code responds nothing:

enter image description here

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.

Was it helpful?

Solution

It's a computed property. Stealing from here, you just need to add a call to RefreshCache 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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top