gmoney1011
Technical User
I have a simple vbscript where I use WMI to pull various server information. I wrote a function to determine if the server is a virtual machine or not. When I call the function I receive "runtime error: Object required", it appears that my function is not exiting properly but I cant figure it out. Im fairly new to vbscript, so any help is appreciated. Ive wrote the script to run on servers so Im not sure how it would behave on a workstation.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If IsVM Then
WScript.Echo "Server Type: Virtual"
WScript.Echo "Service Tag: N/A"
Else
WScript.Echo "Server Type: Physical"
WScript.Echo "SerialNumber: " & objItem.SerialNumber *****I receive the error on this line*****
End If
Next
'**********Function to determine Virtual Machine**********
Function IsVM ()
Dim isvmItems
Set isvmItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In isvmItems
If objItem.Manufacturer = "VMware, Inc." Then
IsVM = "True"
Else
IsVM = "False"
End If
Next
End Function
If I need to post the enitre code or give more information please let me know.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If IsVM Then
WScript.Echo "Server Type: Virtual"
WScript.Echo "Service Tag: N/A"
Else
WScript.Echo "Server Type: Physical"
WScript.Echo "SerialNumber: " & objItem.SerialNumber *****I receive the error on this line*****
End If
Next
'**********Function to determine Virtual Machine**********
Function IsVM ()
Dim isvmItems
Set isvmItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In isvmItems
If objItem.Manufacturer = "VMware, Inc." Then
IsVM = "True"
Else
IsVM = "False"
End If
Next
End Function
If I need to post the enitre code or give more information please let me know.