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.

Re: Determine Workstation or Server? by Richard

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
--



Re: Determine Workstation or Server? by Spyke

Spyke
Tue Apr 27 10:18:38 CDT 2004

"=?Utf-8?B?S1I=?=" <anonymous@discussions.microsoft.com> wrote in
news:F37AE51F-4A01-436A-A424-BA78ED30C1A5@microsoft.com:

> Any server or ws I put in strComputer (put as \\<machine>), I get the
> error message "<machine> does not have WMI installed." Any ideas?
>

Try not putting in the \\, just use <machine>.

--

Cheers,
Spyke

Re: Determine Workstation or Server? by Richard

Richard
Tue Apr 27 10:39:47 CDT 2004

Hi,

The variable strComputer should be the NetBIOS name of the computer. If you
were authenticated on the computer, it would be the value of the
WshNetwork.ComputerName attribute.

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
"Spyke" <spyke@mailinator.com> wrote in message
news:Xns94D872E9A5072spykemailinator.com@207.46.248.16...
> "=?Utf-8?B?S1I=?=" <anonymous@discussions.microsoft.com> wrote in
> news:F37AE51F-4A01-436A-A424-BA78ED30C1A5@microsoft.com:
>
> > Any server or ws I put in strComputer (put as \\<machine>), I get the
> > error message "<machine> does not have WMI installed." Any ideas?
> >
>
> Try not putting in the \\, just use <machine>.
>
> --
>
> Cheers,
> Spyke