I have a AD hosted on 2003R2 and 2008R2, I would like to check the membership for the domain computer (e.g. compA) when an user logs on using that computer (e.g. compA) and perform certain operations inside a script. I think WMI could probably be useful but I am unable to find the proper query to get the list of groups of the computer account in question. Any idea?
Here's a script that I've modified from this site. I haven't tested the code, but it looks sound.
Option Explicit Dim objNetwork, strDomain, strComputer, objComputer, objGroup, strGroupMemberships Dim arrGroupMemberships ' Get the domain and username from the WScript.Network object Set objNetwork = CreateObject("WScript.Network") strDomain = objNetwork.UserDomain strComputer = objNetwork.ComputerName ' Instanciate the user object from the data above Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer) ' Run through the users groups and put them in the string For Each objGroup In objComputer.Groups strGroupMemberships = strGroupMemberships & objGroup.Name & "," Next arrGroupMemberships = Split(strGroupMemberships, ",") ' Loop through array to get groups that this computer is a member of
This should get you going in the right direction if you haven't solved it by now.