-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ad978c
commit c798abb
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
source/Examples/xService_ChangeServiceRecoveryOptions.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#Requires -module 'xPSDesiredStateConfiguration' | ||
|
||
<# | ||
.SYNOPSIS | ||
Configuration that changes the recovery options for an existing service. | ||
.DESCRIPTION | ||
Configuration that changes the recovery options for an existing service. | ||
.PARAMETER Name | ||
The name of the Windows service. | ||
.PARAMETER State | ||
The state that the Windows service should have. | ||
.PARAMETER ResetPeriodSeconds | ||
The time to wait for the Failure count to reset in seconds. | ||
.PARAMETER FailureCommand | ||
The command line to run if a service fails. | ||
.PARAMETER RebootMessage | ||
An optional broadcast message to send to logged in users if the machine reboots as a result of a failure action. | ||
.EXAMPLE | ||
xService_ChangeServiceStateConfig -Name 'spooler' -State 'Stopped' | ||
Compiles a configuration that make sure the state for the Windows | ||
service 'spooler' is 'Stopped'. If the service is running the | ||
Windows service will be stopped. | ||
#> | ||
Configuration xService_ChangeServiceFailureActionsConfig | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name, | ||
|
||
[Parameter()] | ||
[ValidateSet('Running', 'Stopped')] | ||
[System.String] | ||
$State = 'Running', | ||
|
||
[Parameter()] | ||
[System.Int32] | ||
$ResetPeriodSeconds = 86400, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$FailureCommand, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$RebootMessage, | ||
|
||
[Parameter()] | ||
[Switch] | ||
$FailureActionsOnNonCrashFailures | ||
) | ||
|
||
Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' | ||
|
||
Node localhost | ||
{ | ||
xService 'ChangeServiceState' | ||
{ | ||
Name = $Name | ||
State = $State | ||
Ensure = 'Present' | ||
ResetPeriodSeconds = $ResetPeriodSeconds | ||
RebootMessage = $RebootMessage | ||
FailureCommand = $FailureCommand | ||
FailureActionsOnNonCrashFailures = $FailureActionsOnNonCrashFailures | ||
FailureActionsCollection = @( | ||
DSC_xFailureAction | ||
{ | ||
Type = 'RESTART' | ||
DelayMilliSeconds = 60000 | ||
} | ||
DSC_xFailureAction | ||
{ | ||
Type = 'RESTART' | ||
DelayMilliSeconds = 120000 | ||
} | ||
DSC_xFailureAction | ||
{ | ||
Type = 'Reboot' | ||
DelayMilliSeconds = 240000 | ||
} | ||
DSC_xFailureAction | ||
{ | ||
Type = 'RUN_COMMAND' | ||
DelayMilliSeconds = 240000 | ||
} | ||
) | ||
} | ||
} | ||
} |