Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify DC from list of servers

Status
Not open for further replies.

skar

MIS
Mar 21, 2001
37
GB
I was tasked to write a script that would read in a list of servers, connect to each one in turn, find the admin account, reset the password and then echo the results out to text files. One for failures and one for success.

This I did but I found a small problem. The routine that discovers the admin account checks the SID. As we all know the local admin account SID always ends in 500. But if one of the servers is a DC then it finds the domain account and resets that. Not what we wanted.

So what I'm working on is a small routine to check to see if the server being checked is a DC or not. If it is a DC then to skip to the next server in the list.

I'm running into walls and could do with a little help please!
 
>... But if one of the servers is a DC then it finds the domain account and resets that. Not what we wanted.

I would propose a wmi scheme to quickly determine whether it is a local account or not.
[tt]
'given these already within the script
sserver"a0b1c2"
ssid="S-1-5-21-1234567890-2345678901-3456789012-500"

set obj=getobject("winmgmts:\\" & sserver & "\root\cimv2").get _
("win32_sid.sid='" & ssid & "'")
blocal=obj.localaccount 'true local, false global
set obj=nothing
[/tt]
See what it gives?

- tsuji
 
Thanks Tsuji. I've been playing about with your SID scriplet but in the end went for the routine below.

Code:
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputername & "\root\cimv2")

'==========================================================
'Extract the contents of the Win32_ComputerSystem container
'========================================================== 

Set colComputers = objWMIService.ExecQuery _
    ("Select DomainRole from Win32_ComputerSystem")

'=========================================================
'Loop through the results as it is passed back as an array
'=========================================================

for each colItem in colComputers
if colItem.DomainRole = 4 or colItem.DomainRole = 5 then

'========================================================================
'If the computer is a domain controller, this part of the script executes
'========================================================================

	msgbox "This is a domain controller"
	dc = 1
else

'==================================================================
'If the computer is anything else, this part of the script executes
'==================================================================

	msgbox "This is not a domain controller"
	dc = 0
end if
next

This works for me. Many thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top