Skip to content

Commit d5f7cf6

Browse files
committed
Existing unit tests are now green.
Still need to start adding new unit tests.
1 parent 792cd12 commit d5f7cf6

File tree

2 files changed

+199
-80
lines changed

2 files changed

+199
-80
lines changed

source/DSCResources/DSC_xServiceResource/DSC_xServiceResource.psm1

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,57 +2145,58 @@ function Get-ServiceFailureActions {
21452145
$Service
21462146
)
21472147
process {
2148-
$registryData = Get-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\$service
2149-
2150-
$failureActions = [PSCustomObject]@{
2151-
resetPeriodSeconds = $null
2152-
hasRebootMessage = $null
2153-
hasFailureCommand = $null
2154-
failureActionCount = $null
2155-
failureCommand = $null
2156-
rebootMessage = $null
2157-
actionsCollection = $null
2158-
$FailureActionsOnNonCrashFailures = $false
2159-
}
2148+
if($registryData = Get-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\$service -ErrorAction SilentlyContinue)
2149+
{
2150+
$failureActions = [PSCustomObject]@{
2151+
resetPeriodSeconds = $null
2152+
hasRebootMessage = $null
2153+
hasFailureCommand = $null
2154+
failureActionCount = $null
2155+
failureCommand = $null
2156+
rebootMessage = $null
2157+
actionsCollection = $null
2158+
FailureActionsOnNonCrashFailures = $false
2159+
}
21602160

2161-
if($registryData.GetvalueNames() -match 'FailureCommand') {
2162-
$failureActions.failureCommand = $registryData.GetValue('FailureCommand')
2163-
}
2161+
if($registryData.GetvalueNames() -match 'FailureCommand') {
2162+
$failureActions.failureCommand = $registryData.GetValue('FailureCommand')
2163+
}
21642164

2165-
if($registryData.GetValueNames() -match 'RebootMessage') {
2166-
$failureActions.rebootMessage = $registryData.GetValue('RebootMessage')
2167-
}
2165+
if($registryData.GetValueNames() -match 'RebootMessage') {
2166+
$failureActions.rebootMessage = $registryData.GetValue('RebootMessage')
2167+
}
21682168

2169-
if($registryData.GetvalueNames() -match 'FailureActionsOnNonCrashFailures') {
2170-
$failureActions.FailureActionsOnNonCrashFailures = [System.Boolean]$registryData.GetValue('FailureActionsOnNonCrashFailures')
2171-
}
2169+
if($registryData.GetvalueNames() -match 'FailureActionsOnNonCrashFailures') {
2170+
$failureActions.FailureActionsOnNonCrashFailures = [System.Boolean]$registryData.GetValue('FailureActionsOnNonCrashFailures')
2171+
}
21722172

2173-
if($registryData.GetValueNames() -match 'FailureActions')
2174-
{
2175-
$failureActionsBinaryData = $registryData.GetValue('FailureActions')
2173+
if($registryData.GetValueNames() -match 'FailureActions')
2174+
{
2175+
$failureActionsBinaryData = $registryData.GetValue('FailureActions')
21762176

2177-
# The first four bytes represent the Reset Period.
2178-
$failureActions.resetPeriodSeconds = Get-FailureActionsProperty -PropertyName ResetPeriodSeconds -Bytes $failureActionsBinaryData
2177+
# The first four bytes represent the Reset Period.
2178+
$failureActions.resetPeriodSeconds = Get-FailureActionsProperty -PropertyName ResetPeriodSeconds -Bytes $failureActionsBinaryData
21792179

2180-
# Next four bytes indicate the presence of a reboot message in case one of the chosen failure actions is
2181-
# SC_ACTION_REBOOT. The actual value of the message is stored in the 'RebootMessage' property
2182-
$failureActions.hasRebootMessage = Get-FailureActionsProperty -PropertyName HasRebootMsg -Bytes $failureActionsBinaryData
2180+
# Next four bytes indicate the presence of a reboot message in case one of the chosen failure actions is
2181+
# SC_ACTION_REBOOT. The actual value of the message is stored in the 'RebootMessage' property
2182+
$failureActions.hasRebootMessage = Get-FailureActionsProperty -PropertyName HasRebootMsg -Bytes $failureActionsBinaryData
21832183

2184-
# The next four bytes indicate whether a failure action run command exists. This command
2185-
# would be run in the case one of the failure actions chosen is SC_ACTION_RUN_COMMAND
2186-
# If this value is true then the actual command string is stored in the 'FailureCommand' property.
2187-
$failureActions.hasFailureCommand = Get-FailureActionsProperty -PropertyName HasFailureCommand -Bytes $failureActionsBinaryData
2184+
# The next four bytes indicate whether a failure action run command exists. This command
2185+
# would be run in the case one of the failure actions chosen is SC_ACTION_RUN_COMMAND
2186+
# If this value is true then the actual command string is stored in the 'FailureCommand' property.
2187+
$failureActions.hasFailureCommand = Get-FailureActionsProperty -PropertyName HasFailureCommand -Bytes $failureActionsBinaryData
21882188

2189-
# These four bytes give the count of how many reboot failure actions have been defined.
2190-
$failureActions.failureActionCount = Get-FailureActionsProperty -PropertyName FailureActionCount -Bytes $failureActionsBinaryData
2189+
# These four bytes give the count of how many reboot failure actions have been defined.
2190+
$failureActions.failureActionCount = Get-FailureActionsProperty -PropertyName FailureActionCount -Bytes $failureActionsBinaryData
21912191

2192-
if($failureActions.failureActionCount -gt 0)
2193-
{
2194-
$failureActions.ActionsCollection = Get-FailureActionCollection -Bytes $failureActionsBinaryData -ActionsCount $failureActions.failureActionCount
2192+
if($failureActions.failureActionCount -gt 0)
2193+
{
2194+
$failureActions.ActionsCollection = Get-FailureActionCollection -Bytes $failureActionsBinaryData -ActionsCount $failureActions.failureActionCount
2195+
}
21952196
}
2196-
}
21972197

2198-
$failureActions
2198+
$failureActions
2199+
}
21992200
}
22002201
}
22012202

0 commit comments

Comments
 (0)