#160113 - 2006-03-31 03:43 PM
a script to hit every server in a domain and verify guest is disabled?
|
Ronan_Condon
Fresh Scripter
Registered: 2006-03-30
Posts: 18
|
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.
|
|
Top
|
|
|
|
#160114 - 2006-03-31 03:50 PM
Re: a script to hit every server in a domain and verify guest is disabled?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
It would be easier to use the ADSI WinNT:// provider to connect to the Guest account and check its status.
Search the board for "WinNT://" and "AccountDisabled" for some examples.
|
|
Top
|
|
|
|
#160116 - 2006-03-31 04:39 PM
Re: a script to hit every server in a domain and verify guest is disabled?
|
Ronan_Condon
Fresh Scripter
Registered: 2006-03-30
Posts: 18
|
Ah thats terrific thanks a lot! I used the following code modified from one of the posts: Code:
Break ON $colUser=getobject("WinNT://@DOMAIN") $colUser.filter="user" "" For Each $user In $colUser If $user.FullName For Each $Group In $user.groups If $group.name = "Guests" if ($User.AccountDisabled=0) ? $User.FullName +" is NOT disabled!" Endif EndIf Next EndIf Next Exit 0
Two questions - 1) How do I target a standalone server, is it as simple as doing $colUser=getobject("WinNT://myservername")?? If so, do I need to do a runas for the command window im running from our main server seeing as there is no trust between them? (basically talking about a data centre with multiple domains and standalone servers all on same network, but with a common admin/support account that can access all of them)
2) Where im using ? $User.FullName +" is NOT disabled!", I had tried to use the User.Caption, which would show SERVER1\Guest and SERVER2\Guest rather than just "Guest" twice, I got the caption bit from the WMI Class which has worked before but its returning blank when I sub it in here, is the ADSI different to what I have been getting used to?
Thanks again.
Ronan.
|
|
Top
|
|
|
|
#160117 - 2006-03-31 04:53 PM
Re: a script to hit every server in a domain and verify guest is disabled?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Yes it is just about that simple...
$oGuestAcct = getobject("WinNT://$ComputerName/Guest,user")
$oGuestGrp = getobject("WinNT://$ComputerName/Guests,group")
I would avoid running enumerations of all objects unless it is absolutely necessary.
|
|
Top
|
|
|
|
#160119 - 2006-03-31 05:02 PM
Re: a script to hit every server in a domain and verify guest is disabled?
|
Ronan_Condon
Fresh Scripter
Registered: 2006-03-30
Posts: 18
|
thats great cheers for the help howard
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 927 anonymous users online.
|
|
|