Richard
Mon Apr 26 21:06:00 CDT 2004
KR wrote:
> How, using VBScript, would I be able to determine if a computer is a WS or
Server in AD? I have a script (WSH) that queries each computer in AD. If a
computer is a Server, I would like certain code executed on it. I would
like to use it in "If <server> then". Is there some type of property that
would tell me this? Please let me know.
Hi,
You can use WMI to determine the computer role. For example:
' Specify NetBIOS name of the computer.
strComputer = "MyComputer"
' Trap the error if WMI is not installed, or if the computer
' is off line.
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo strComputer & " does not have WMI installed"
Else
On Error GoTo 0
Set colComputers = objWMIService.ExecQuery _
("SELECT * FROM Win32_ComputerSystem")
For Each objComputer In colComputers
intRole = objComputer.DomainRole
Select Case intRole
Case 0
strRole = " is a standalone workstation"
Case 1
strRole = " is a member workstation"
Case 2
strRole = " is a standalone server"
Case 3
strRole = " is a member server"
Case 4
strRole = " is a backup domain controller"
Case 5
strRole = " is a primary domain controller"
End Select
Wscript.Echo strComputer & strRole
Next
End If
Clients with W2k or above have WMI, and it can be installed on NT and Win9x
machines.
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site -
http://www.rlmueller.net
--