54 lines
2.5 KiB
PowerShell
54 lines
2.5 KiB
PowerShell
function ConvertFrom-FailureActions {
|
|
param (
|
|
[byte[]]$FailureActions
|
|
)
|
|
begin {
|
|
$logLead = (Get-LogLeadName)
|
|
|
|
$defaultTypeName = 'ServiceFailureAction'
|
|
$defaultKeys = @('ActionTypes')
|
|
$defaultDisplaySet = @('ResetPeriod','ActionTypes','Command','RebootMessage')
|
|
$defaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet('DefaultDisplayPropertySet',[string[]]$defaultDisplaySet)
|
|
$defaultKeyPropertySet = New-Object System.Management.Automation.PSPropertySet('DefaultKeyPropertySet',[string[]]$defaultKeys)
|
|
$PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]@($defaultDisplayPropertySet,$defaultKeyPropertySet)
|
|
}
|
|
process {
|
|
if ($null -eq $FailureActions) {
|
|
return $null
|
|
}
|
|
|
|
$actionLookup = ('None','Restart','Reboot','RunCommand')
|
|
$parsedResetPeriod = [System.BitConverter]::ToInt32($FailureActions[0..3],0)
|
|
$parsedRebootMsg = [System.BitConverter]::ToInt32($FailureActions[4..7],0)
|
|
$parsedCommand = [System.BitConverter]::ToInt32($FailureActions[8..11],0)
|
|
$parsedActions = [System.BitConverter]::ToInt32($FailureActions[12..15],0)
|
|
$parsedActionPointer = [System.BitConverter]::ToInt32($FailureActions[16..19],0)
|
|
$lpsaActionsStart = $parsedActionPointer
|
|
|
|
$actions = @()
|
|
for($i = 0; $i -lt $parsedActions; $i++) {
|
|
$actionType = $actionLookup[[System.BitConverter]::ToInt32($FailureActions[$lpsaActionsStart..$($lpsaActionsStart+3)],0)]
|
|
$lpsaActionsStart += 4
|
|
$actionDelay = [System.BitConverter]::ToInt32($FailureActions[$lpsaActionsStart..$($lpsaActionsStart+3)],0)
|
|
$lpsaActionsStart += 4
|
|
if ($actionType -ne 'None') {
|
|
$actions += @{
|
|
Type = $actionType
|
|
Delay = [System.TimeSpan]::FromSeconds($actionDelay)
|
|
}
|
|
}
|
|
}
|
|
|
|
$properties = @{
|
|
Actions = $actions
|
|
ActionTypes = $actions.Type -join ','
|
|
Command = $parsedCommand
|
|
ResetPeriod = [System.TimeSpan]::FromSeconds($parsedResetPeriod)
|
|
RebootMessage = $parsedRebootMsg
|
|
}
|
|
$failureAction = New-Object PSCustomObject -Property $properties
|
|
$failureAction.PSObject.TypeNames.Insert(0,$defaultTypeName)
|
|
$failureAction | Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $PSStandardMembers
|
|
return $failureAction
|
|
}
|
|
} |