@@ -2145,57 +2145,58 @@ function Get-ServiceFailureActions {
2145
2145
$Service
2146
2146
)
2147
2147
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
+ }
2160
2160
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
+ }
2164
2164
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
+ }
2168
2168
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
+ }
2172
2172
2173
- if ($registryData.GetValueNames () -match ' FailureActions' )
2174
- {
2175
- $failureActionsBinaryData = $registryData.GetValue (' FailureActions' )
2173
+ if ($registryData.GetValueNames () -match ' FailureActions' )
2174
+ {
2175
+ $failureActionsBinaryData = $registryData.GetValue (' FailureActions' )
2176
2176
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
2179
2179
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
2183
2183
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
2188
2188
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
2191
2191
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
+ }
2195
2196
}
2196
- }
2197
2197
2198
- $failureActions
2198
+ $failureActions
2199
+ }
2199
2200
}
2200
2201
}
2201
2202
0 commit comments