Skip to content

Commit

Permalink
Fix error if key already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomNoun7 committed May 6, 2020
1 parent fbbfc64 commit 4039164
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
40 changes: 20 additions & 20 deletions source/DSCResources/DSC_xServiceResource/DSC_xServiceResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ function Set-ServiceFailureActionProperty {
# This setting is a combination a flag in the _SERVICE_FAILURE_ACTIONSA struct,
# and the actual string value for the message stored in the 'RebootMessage' registry property.
# If hasRebootMessage is already true, then we know the key exists and we can just set it.
if ($failureActions.hasRebootMessage)
if (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'RebootMessage' -ErrorAction SilentlyContinue)
{
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'RebootMessage' -Value $RebootMessage | Out-Null
}
Expand All @@ -2411,7 +2411,7 @@ function Set-ServiceFailureActionProperty {
# 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.
if ($PSBoundParameters.ContainsKey('FailureCommand'))
{
if ($failureActions.hasFailureCommand)
if (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureCommand' -ErrorAction SilentlyContinue)
{
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureCommand' -Value $FailureCommand | Out-Null
}
Expand Down Expand Up @@ -2451,7 +2451,7 @@ function Set-ServiceFailureActionProperty {
# if it doesn't already exist.
if ($PSBoundParameters.ContainsKey('FailureActionsOnNonCrashFailures'))
{
if ($failureActions.FailureActionsOnNonCrashFailures) {
if (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureActionsOnNonCrashFailures' -ErrorAction SilentlyContinue) {
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName -Name 'FailureActionsOnNonCrashFailures' -Value $FailureActionsOnNonCrashFailures | Out-Null
}
else
Expand All @@ -2463,23 +2463,23 @@ function Set-ServiceFailureActionProperty {
}

function Test-HasRestartFailureAction
{
[CmdletBinding()]
param (
[Parameter()]
[System.Object[]]
$Collection
)

process {
$hasRestartAction = $false

foreach ($action in $collection) {
if ($action.type -eq 'RUN_COMMAND') {
$hasRestartAction = $true
}
}
{
[CmdletBinding()]
param (
[Parameter()]
[System.Object[]]
$Collection
)

process {
$hasRestartAction = $false

$hasRestartAction
foreach ($action in $collection) {
if ($action.type -eq 'RUN_COMMAND') {
$hasRestartAction = $true
}
}

$hasRestartAction
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DSC_xServiceResource : OMI_BaseResource
[Write,Description("The command line to run if a service fails.")] String FailureCommand;
[Write,EmbeddedInstance("DSC_xFailureAction"),Description("The actions to take when a service fails.")] String FailureActionsCollection[];
[Write,Description("A flag indicating whether failure actions should be invoked on non-crash failures.")] Boolean FailureActionsOnNonCrashFailures;
[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;
};

[ClassVersion("1.0.0")]
Expand Down

0 comments on commit 4039164

Please sign in to comment.