PC Review Forums Newsgroups Windows XP Windows XP WMI Recursively removing domain groups/users from local machine

Reply

Recursively removing domain groups/users from local machine

 
Thread Tools Rate Thread
Old 01-07-2004, 05:40 PM   #1
Chris Sharp
Guest
 
Posts: n/a
Default Recursively removing domain groups/users from local machine


I seem to be stuck on the proper binding method or deletion method to the
members of the local groups who are domain groups/users.
The other problem is in determining if it's a group or user when deleting
the object. Much appreciated for any help! -CPSharp


Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems2 = objWMIService.ExecQuery("Select Name from Win32_Group" _
& " Where LocalAccount=True")

For Each objGroup In colItems2
Set filtGroups = GetObject("WinNT://" & strComputer & "/" & objGroup.Name
& ",group")
Set filtObjects = GetObject("WinNT://" & strComputer & "/" &
filtGroups.Members) 'not sure if this is working

For each objLocalGrp in filtGroups.Members

If InStr(1, objLocalGrp.ADsPath, strComputer, vbTextCompare) = 0 AND _
InStr(1, objLocalGrp.ADsPath, "MYDOMAIN", vbTextCompare) <> 0 Then
objLocalGrp.Delete "user", objLocalGrp.Name
objLocalGrp.Delete "group", objLocalGrp.Name
End If


Next
Next

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off