WMI functional Check Probe

Microsoft.SystemCenter.WMIFunctionalCheck.Probe (ProbeActionModuleType)

Probe for the WMI Functional Check

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
Probe ProbeAction Microsoft.Windows.PowerShellPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Time out SecondsTime to wait until cancel execution of script expressed in seconds

Source Code:

<ProbeActionModuleType ID="Microsoft.SystemCenter.WMIFunctionalCheck.Probe" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Probe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>WMIFunctionalCheck.ps1</ScriptName>
<ScriptBody><Script>
#Copyright (c) Microsoft Corporation. All rights reserved.

#*************************************************************************
# $ScriptName: "WMIFunctionalCheck" $
#
# Purpose: This script runs a WMI functional check.
#
# $File: WMIFunctionalCheck.ps1 $
#*************************************************************************

Param([string]$ComputerName)

#OS version for Win 2012
$WIN_OS_2012_Ver = "6.2"
$OSRegistryKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"

#******************************************************************************
# FUNCTION: CheckMinOSVer
# DESCRIPTION: Returns True if the Registry Key for CurrentVersion
# is equal or Higher than the Minimum OS Versions Number.
# PARAMETER: DblMinVer Minimum Version Number to use
# RETURNS: Boolean: True, if build is greater or equal than the given number
#******************************************************************************
function CheckByOSCurrentVersion() #As Boolean
{
$strCurrentOSVer = Get-ItemProperty $OSRegistryKey
$strCurrentOSVer = $strCurrentOSVer.CurrentVersion
if($strCurrentOSVer -ge $WIN_OS_2012_Ver)
{
return $true;
}
return $false;
}

#---------------------------------------------------------------------------
# Retrieves the script output.
#---------------------------------------------------------------------------
function ReturnResponse($boolErrorFlag, $strMessage)
{
if($boolErrorFlag -eq $true)
{
$propertyBag.AddValue("Status", "FAIL")
$propertyBag.AddValue("ErrorMessage", $strMessage)
}
else
{
$propertyBag.AddValue("Status", "OK")
}
$api.LogScriptEvent("WMIFunctionalCheck.ps1", 100, $EVENT_TYPE_INFORMATION, $strMessage)
$propertyBag
}


#---------------------------------------------------------------------------
# Execute a WMI Query.
#---------------------------------------------------------------------------
function ExecuteWMIQuery($targetComputer, $strBaseClass, $strQuery, $strPropertyName)
{
if($isHigherThanWin08 -eq $true)
{
try{
$wbemObjectSet = Get-CimInstance -ComputerName $targetComputer -Namespace $("root\" + $strBaseClass) -Query $strQuery
}catch{
$error.Clear()
import-module cimcmdlets
$wbemObjectSet = Get-CimInstance -ComputerName $targetComputer -Namespace $("root\" + $strBaseClass) -Query $strQuery
}
}
else
{
$wbemObjectSet = Get-WMIObject -Namespace $("root\" + $strBaseClass) -ComputerName $targetComputer -Query $strQuery
}
foreach($objItem in $wbemObjectSet)
{
$temp = $objItem.$strPropertyName
}
return $temp
}


#---------------------------------------------------------------------------
# Gets WMI Status.
#---------------------------------------------------------------------------
function GetWMIStatus($strComputerName)
{
$status = ExecuteWMIQuery $strComputerName "cimv2" "select Status from win32_operatingsystem" "Status"
if($status -eq "OK")
{
return "OK"
}
else
{
return "FAIL"
}
}

#Check the OS version
$isHigherThanWin08 = CheckByOSCurrentVersion

#Define local event constants
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4

#Create PropertyBag object
$api = new-object -comObject "MOM.ScriptAPI"
$propertyBag = $api.CreatePropertyBag()

$error.Clear()

#Set variables
$strWMIStatus = GetWMIStatus $ComputerName

if($error.Count -ne 0)
{
$strMessageToUse = "Error Details: " + $error[0]
ReturnResponse $true $strMessageToUse
}
else
{
$strMessageToUse = "Script WMIFunctionalCheck executed Successfully"
ReturnResponse $false $strMessageToUse
}





</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>ComputerName</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Probe"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>