Recursively removing domain groups/users from local machine

C

Chris Sharp

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top