Hi there,
Im new to WMI scripting, started learning it on tuesday last to be honest, what I'm trying to do is basically hit every server in a domain and verify that any guest accounts on the server are disabled. I've tried looking up various examples etc, and was looking through this site but couldnt come up with anything. apologies if there is something here on the site for that sort of thing already but ive spent so much time getting some form of understanding of the scripting etc and i practically have the boss standing here tapping his foot looking at his watch at this stage for this script hehe.
anyway, what im trying to do on a simplified level is, for example, connect to SERVER1, pull a user list, and for each user, IF its a member of the "Guests" group, check if its disabled. This also has to be run from another machine, i am basically going to be loading each Server name into an array running it "FOR EACH" one of them.
I had been trying the INGROUP() function after something like:
Code:
$objWMIService = GetObject("winmgmts:\\"+ $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_UserAccount")
For Each $objItem in $colItems
IF ($objItem.Name = "Guest")
IF INGROUP("Guests")
then i realised the INGROUP command only works for the currently logged on user. The first line up there aswell, I havent been able to connect to any machines, just run the script on a local computer with $computer="."
Any examples I found on the web were using the Impersonate thing, but that hasnt worked for me either. Using the examples off the net, i was using something like:
Code:
$strComputer = "SERVER1"
$objWMIService = GetObject("winmgmts: {impersonationLevel=impersonate}!//" & $strComputer & "/root/cimv2")
but that didnt work either.
This is driving me nuts, if anyone can give me any idea or a sample that will work I would appreciate it.
Ronan.