Skip to content

Commit 4039164

Browse files
committed
Fix error if key already exists.
1 parent fbbfc64 commit 4039164

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

source/DSCResources/DSC_xServiceResource/DSC_xServiceResource.psm1

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ function Set-ServiceFailureActionProperty {
23932393
# This setting is a combination a flag in the _SERVICE_FAILURE_ACTIONSA struct,
23942394
# and the actual string value for the message stored in the 'RebootMessage' registry property.
23952395
# If hasRebootMessage is already true, then we know the key exists and we can just set it.
2396-
if ($failureActions.hasRebootMessage)
2396+
if (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'RebootMessage' -ErrorAction SilentlyContinue)
23972397
{
23982398
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'RebootMessage' -Value $RebootMessage | Out-Null
23992399
}
@@ -2411,7 +2411,7 @@ function Set-ServiceFailureActionProperty {
24112411
# This is the same as the RebootMessage property above. It's a combination of a flag in the struct, and an external property that stores the value.
24122412
if ($PSBoundParameters.ContainsKey('FailureCommand'))
24132413
{
2414-
if ($failureActions.hasFailureCommand)
2414+
if (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureCommand' -ErrorAction SilentlyContinue)
24152415
{
24162416
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureCommand' -Value $FailureCommand | Out-Null
24172417
}
@@ -2451,7 +2451,7 @@ function Set-ServiceFailureActionProperty {
24512451
# if it doesn't already exist.
24522452
if ($PSBoundParameters.ContainsKey('FailureActionsOnNonCrashFailures'))
24532453
{
2454-
if ($failureActions.FailureActionsOnNonCrashFailures) {
2454+
if (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureActionsOnNonCrashFailures' -ErrorAction SilentlyContinue) {
24552455
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureActionsOnNonCrashFailures' -Value $FailureActionsOnNonCrashFailures | Out-Null
24562456
}
24572457
else
@@ -2463,23 +2463,23 @@ function Set-ServiceFailureActionProperty {
24632463
}
24642464

24652465
function Test-HasRestartFailureAction
2466-
{
2467-
[CmdletBinding()]
2468-
param (
2469-
[Parameter()]
2470-
[System.Object[]]
2471-
$Collection
2472-
)
2473-
2474-
process {
2475-
$hasRestartAction = $false
2476-
2477-
foreach ($action in $collection) {
2478-
if ($action.type -eq 'RUN_COMMAND') {
2479-
$hasRestartAction = $true
2480-
}
2481-
}
2466+
{
2467+
[CmdletBinding()]
2468+
param (
2469+
[Parameter()]
2470+
[System.Object[]]
2471+
$Collection
2472+
)
2473+
2474+
process {
2475+
$hasRestartAction = $false
24822476

2483-
$hasRestartAction
2477+
foreach ($action in $collection) {
2478+
if ($action.type -eq 'RUN_COMMAND') {
2479+
$hasRestartAction = $true
2480+
}
24842481
}
2482+
2483+
$hasRestartAction
24852484
}
2485+
}

source/DSCResources/DSC_xServiceResource/DSC_xServiceResource.schema.mof

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DSC_xServiceResource : OMI_BaseResource
2020
[Write,Description("The command line to run if a service fails.")] String FailureCommand;
2121
[Write,EmbeddedInstance("DSC_xFailureAction"),Description("The actions to take when a service fails.")] String FailureActionsCollection[];
2222
[Write,Description("A flag indicating whether failure actions should be invoked on non-crash failures.")] Boolean FailureActionsOnNonCrashFailures;
23+
[Write,Description("An optional broadcast message to send to logged in users if the machine reboots as a result of a failure action.")] String RebootMessage;
2324
};
2425

2526
[ClassVersion("1.0.0")]

0 commit comments

Comments
 (0)