69 lines
2.0 KiB
PowerShell
69 lines
2.0 KiB
PowerShell
$deviceID = # The ID of the agent watchdog in Base64 format, provided when the AMT_AgentPresenceWatchdog was created.
|
|
$agentPresenceWatchdogRef = $wsmanConnectionObject.NewReference("SELECT * FROM AMT_AgentPresenceWatchdog WHERE DeviceID='" + $deviceID + "'")
|
|
|
|
# RegisterAgent method
|
|
$inputObject = $agentPresenceWatchdogRef.CreateMethodInput("RegisterAgent")
|
|
$outputObject = $agentPresenceWatchdogRef.InvokeMethod($inputObject)
|
|
$returnValue = $outputObject.GetProperty("ReturnValue")
|
|
if($returnValue -like "0")
|
|
{
|
|
[String]$sessionSequenceNumberString = $outputObject.GetProperty("SessionSequenceNumber")
|
|
if($sessionSequenceNumber -le [UInt32]::MaxValue)
|
|
{
|
|
$sessionSequenceNumber = ([UInt32]$sessionSequenceNumberString) ++
|
|
}
|
|
else
|
|
{
|
|
$sessionSequenceNumber = 0
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Write-Host -ForegroundColor Red "Failed to perform method RegisterAgent, with error:"$returnValue.ToString()
|
|
return
|
|
}
|
|
|
|
# AssertPresence method
|
|
$inputObject = $agentPresenceWatchdogRef.CreateMethodInput("AssertPresence")
|
|
# Send heartbeat to the agent
|
|
For ( $i = 1; $i -le 10; $i+=1 )
|
|
{
|
|
$inputObject.SetProperty("SequenceNumber",[string]$sessionSequenceNumber)
|
|
$outputObject = $agentPresenceWatchdogRef.InvokeMethod($inputObject)
|
|
$returnValue = $outputObject.GetProperty("ReturnValue")
|
|
IF($returnValue.ToString() -eq "0")
|
|
{
|
|
IF($sessionSequenceNumber -le [UInt32]::MaxValue)
|
|
{
|
|
$sessionSequenceNumber ++
|
|
}
|
|
ELSE
|
|
{
|
|
$sessionSequenceNumber = 0
|
|
}
|
|
}
|
|
ELSE
|
|
{
|
|
Write-Host -ForegroundColor Red "Failed to perform method AssertPresence, with error:"$returnValue.ToString()
|
|
break
|
|
}
|
|
Start-Sleep -Seconds 10
|
|
}
|
|
|
|
|
|
# AssertShutdown method
|
|
$inputObject = $agentPresenceWatchdogRef.CreateMethodInput("AssertShutdown")
|
|
$inputObject.SetProperty("SequenceNumber",[String]$sessionSequenceNumber)
|
|
$outputObject = $agentPresenceWatchdogRef.InvokeMethod($inputObject)
|
|
$returnValue = $outputObject.GetProperty("ReturnValue")
|
|
IF($returnValue.ToString() -ne "0")
|
|
{
|
|
Write-Host -ForegroundColor Red "Failed to perform method AssertShutdown, with error:"$returnValue.ToString()
|
|
Return
|
|
}
|
|
|
|
|
|
|
|
|
|
|