Hyper-V Host Attestation WMI-based Monitor

Microsoft.SystemCenter.VirtualMachineManager.AttestationWmiMonitor (UnitMonitor)

Monitors whether the Hyper-V host has attestation problems by getting information through WMI

Element properties:

TargetMicrosoft.SystemCenter.VirtualMachineManager.HyperVHost
Parent MonitorMicrosoft.SystemCenter.VirtualMachineManager.AttestationMonitor
CategorySecurityHealth
EnabledTrue
Alert GenerateFalse
Alert Auto ResolveFalse
Monitor TypeMicrosoft.SystemCenter.VirtualMachineManager.TimedPowershell.TwoStatesMonitorType
RemotableTrue
AccessibilityPublic
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SystemCenter.VirtualMachineManager.AttestationWmiMonitor" Accessibility="Public" Enabled="true" Target="VMMBase!Microsoft.SystemCenter.VirtualMachineManager.HyperVHost" ParentMonitorID="Microsoft.SystemCenter.VirtualMachineManager.AttestationMonitor" Remotable="true" Priority="Normal" TypeID="Microsoft.SystemCenter.VirtualMachineManager.TimedPowershell.TwoStatesMonitorType" ConfirmDelivery="true">
<Category>SecurityHealth</Category>
<OperationalStates>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>3600</IntervalSeconds>
<TimeoutSeconds>60</TimeoutSeconds>
<ScriptName>CheckAttestationState.ps1</ScriptName>
<ScriptBody><Script>#Checks the AttestationState
#Arg 0 : Host name
param($HostComputerName)

function DoesHostHaveNoAttestationProblems
{
param($hostComputerName)

$WbemLocator = New-Object -ComObject "WbemScripting.SWbemLocator"
$error.Clear()
$wbemService = $WbemLocator.ConnectServer($hostComputerName, "root\Microsoft\Windows\Hgs")
if($error -ne $null -and $error.Count -gt 0)
{
#Failing to find the WMI namespace means that the HGS client feature is not installed. This does not mean that there is a problem.
$error.Clear()
return $true
}
else
{
$clientConfig = Invoke-CimMethod -ClassName MSFT_HgsClientConfiguration -Namespace "root\Microsoft\Windows\Hgs" -MethodName "Get" -ComputerName $hostComputerName
#If the serverurl and Protectionserverurl are both not populated OR if they are populated and isHostguarded returns true then we know we are good
#bug fix 9107289
$attestationServerUrl = $clientConfig.cmdletOutput.AttestationServerUrl
$keyProtectionServerUrl = $clientConfig.cmdletOutput.KeyProtectionServerUrl
return ((($attestationServerUrl -eq "" -or $attestationServerUrl -eq $null ) -and ($keyProtectionServerUrl -eq "" -or $keyProtectionServerUrl -eq $null) ) -or $clientConfig.cmdletOutput.IsHostGuarded)
}
}

$momApi = new-Object -comObject "Mom.ScriptAPI"
$momBag = $momApi.CreatePropertyBag()
$hostComputerName =$HostComputerName
if($hostComputerName -eq $null)
{
$momApi.LogScriptEvent("CheckAttestationState.ps1",101,1,"CheckAttestationState was called with an invalid computer name and was not executed.")
$momBag.AddValue("HasNoAttestationProblem", $false)
}
else
{
$hasNoAttestationProblems = DoesHostHaveNoAttestationProblems($hostComputerName)
if($Error -ne $null -and $Error.Count -gt 0)
{

$hasNoAttestationProblems = $false;
}

if($hasNoAttestationProblems -eq $false)
{
$momApi.LogScriptEvent("CheckAttestationState.ps1", 101, 0, "Host " + $hostComputerName + " has a problem with attestation.")
}
$momBag.AddValue("HasNoAttestationProblem", $hasNoAttestationProblems)

}
$momBag
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>HostComputerName</Name>
<Value>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</Value>
</Parameter>
</Parameters>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasNoAttestationProblem']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">false</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasNoAttestationProblem']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>