问题
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:
Obviously, my code responds nothing:
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.
回答1:
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)
来源:https://stackoverflow.com/questions/15827491/ad-group-does-not-have-a-primarygrouptoken-attribute