I am trying to query a servers Model and based on a specific type of model then run some other code.
I have done the below but the server I ran it on is not a Gen9
but VMware
so, the result is coming back as the Else
statement in the below - which is incorrect result I expect.
If I run debugging then colItems
is empty (ie this is true since the server I ran is VMWare) - is my statement of this the problem - ie, I think it should not be nothing but cannot find out what else I can change it to? If colItems Is Nothing Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Model Like 'Gen9%'")
If colItems Is Nothing Then
WScript.Echo "This is not a Gen9 Server"
Else
WScript.Echo "This IS a Gen9 Server"
End If
RESULT: (this is not correct result I am expecting)
D:\>cscript Intel_Teaming_Install.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
This IS a Gen9 Server
It doesn't matter if the server matches or not the query. The objWMIService.ExecQuery
call will always (if there are no errors) return a collection. This collection will hold the matching instances or will be empty (no items in the collection).
In your case
If colItems.Count < 1 Then
WScript.Echo "This is not a Gen9 Server"
Else
WScript.Echo "This IS a Gen9 Server"
End If