Loading
Scriptbox
 VBScript Links 
 About VBscript 
 JavaScript Links 
 About JavaScript 
 Powershell Links 
 PSCRIPT the Script Launcher 
 PowerShell Shortcut Keys 
 About Powershell 
     VBScript
    JavaScript
    Powershell
Disclaimer
Contact
Latest 10 Scripts
Script search
  :: { Category } :: 0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ
         

Search Options:  List  the  Active  Directory  Groups  a  User  Belongs  To  

 Content of List the Active Directory Groups a User Belongs To.vbs
MD5 Hash: 7A8450894B126780ECB2F768A1C2B225
' Description: Returns a list of all the Active Directory security groups (including the primary group) that include the MyerKen user account as a member.


On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D

Set objUser = GetObject _
("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intPrimaryGroupID = objUser.Get("primaryGroupID")
arrMemberOf = objUser.GetEx("memberOf")

If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "The memberOf attribute is not set."
Else
WScript.Echo "Member of: "
For Each Group in arrMemberOf
WScript.Echo Group
Next
End If

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
";(objectCategory=Group);" & _
"distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute

Do Until objRecordset.EOF
If objRecordset.Fields("primaryGroupToken") = intPrimaryGroupID Then
WScript.Echo "Primary group:"
WScript.Echo objRecordset.Fields("distinguishedName") & _
" (primaryGroupID: " & intPrimaryGroupID & ")"
End If
objRecordset.MoveNext
Loop

objConnection.Close

   © 2008 - 2013 Boris Toll      :: Scripts available: 6.481 ::      :: scriptbox.toll.at ::      :: powered by www.toll.at ::
  Google Entries:n/a
  Yahoo Backlinks:n/a
  Live Backlinks:n/a
  del.icio.us Bookmarks:n/a
  Technorati Links:n/a