Page 1 of 1 1
Topic Options
#160113 - 2006-03-31 03:43 PM a script to hit every server in a domain and verify guest is disabled?
Ronan_Condon Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#160115 - 2006-03-31 03:50 PM Re: a script to hit every server in a domain and verify guest is disabled?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Instead of WMI, look to ADSI. There are tons of examples on the board.

Edged out by Howard


Edited by Les (2006-03-31 03:51 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#160118 - 2006-03-31 04:57 PM Re: a script to hit every server in a domain and verify guest is disabled?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
See MSDN for information about ADSI. ADSI has it own properties and methods. They differ slightly if you use the WinNT:// or LDAP:// providers.

http://msdn.microsoft.com/library/defaul...adsi_object.asp

http://msdn.microsoft.com/library/defaul..._properties.asp

http://msdn.microsoft.com/library/defaul..._attributes.asp

they will get you going. Continue to search and explore topics on ADSI.


Edited by Howard Bullock (2006-03-31 04:58 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

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 Offline
Fresh Scripter

Registered: 2006-03-30
Posts: 18
thats great cheers for the help howard
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org