So a seemingly impossible task has been handed to me.
we are in the process of migrating domains and i need to make sure the CIO who did/does a lot of development work doesn't have his old domain account tied to anything important like services.
that said. I was thinking i could write a WMI script to poll the servers for any specific accounts in the local admin groups on the servers.
So i've been using scriptomatic to try this out and i can almost get what i want. But i cannot get it to specify the group in the code.
i'm trying to figure out if it would be worth it to do this in visual studio instead just so i can see any code errors.
anyone ever done anything like this? soon as i add WHERE to the SELECT it breaks.
This is the basic Group users code scriptomatic generates. it works but it essentially pulls every domain account when it hits the Domain Users group.
Code:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("PC")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "GroupComponent: " & objItem.GroupComponent
WScript.Echo "PartComponent: " & objItem.PartComponent
WScript.Echo
Next
Next
If i add a WHERE to that such as this it will no longer run. i've also tried sticking the strComputer string in for the "PC" because it will be run with several targets eventually.
Code:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("PC")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser WHERE GroupComponent = ""Win32_Group.Domain='PC',Name='Administrators'""", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "GroupComponent: " & objItem.GroupComponent
WScript.Echo "PartComponent: " & objItem.PartComponent
WScript.Echo
Next
Next