|
| 1 | +#Requires -module 'xPSDesiredStateConfiguration' |
| 2 | + |
| 3 | +<# |
| 4 | + .SYNOPSIS |
| 5 | + Configuration that changes the recovery options for an existing service. |
| 6 | +
|
| 7 | + .DESCRIPTION |
| 8 | + Configuration that changes the recovery options for an existing service. |
| 9 | +
|
| 10 | + .PARAMETER Name |
| 11 | + The name of the Windows service. |
| 12 | +
|
| 13 | + .PARAMETER State |
| 14 | + The state that the Windows service should have. |
| 15 | +
|
| 16 | + .PARAMETER ResetPeriodSeconds |
| 17 | + The time to wait for the Failure count to reset in seconds. |
| 18 | +
|
| 19 | + .PARAMETER FailureCommand |
| 20 | + The command line to run if a service fails. |
| 21 | +
|
| 22 | + .PARAMETER RebootMessage |
| 23 | + An optional broadcast message to send to logged in users if the machine reboots as a result of a failure action. |
| 24 | +
|
| 25 | + .EXAMPLE |
| 26 | + xService_ChangeServiceStateConfig -Name 'spooler' -State 'Stopped' |
| 27 | +
|
| 28 | + Compiles a configuration that make sure the state for the Windows |
| 29 | + service 'spooler' is 'Stopped'. If the service is running the |
| 30 | + Windows service will be stopped. |
| 31 | +#> |
| 32 | +Configuration xService_ChangeServiceFailureActionsConfig |
| 33 | +{ |
| 34 | + [CmdletBinding()] |
| 35 | + param |
| 36 | + ( |
| 37 | + [Parameter(Mandatory = $true)] |
| 38 | + [System.String] |
| 39 | + $Name, |
| 40 | + |
| 41 | + [Parameter()] |
| 42 | + [ValidateSet('Running', 'Stopped')] |
| 43 | + [System.String] |
| 44 | + $State = 'Running', |
| 45 | + |
| 46 | + [Parameter()] |
| 47 | + [System.Int32] |
| 48 | + $ResetPeriodSeconds = 86400, |
| 49 | + |
| 50 | + [Parameter()] |
| 51 | + [System.String] |
| 52 | + $FailureCommand, |
| 53 | + |
| 54 | + [Parameter()] |
| 55 | + [System.String] |
| 56 | + $RebootMessage, |
| 57 | + |
| 58 | + [Parameter()] |
| 59 | + [Switch] |
| 60 | + $FailureActionsOnNonCrashFailures |
| 61 | + ) |
| 62 | + |
| 63 | + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' |
| 64 | + |
| 65 | + Node localhost |
| 66 | + { |
| 67 | + xService 'ChangeServiceState' |
| 68 | + { |
| 69 | + Name = $Name |
| 70 | + State = $State |
| 71 | + Ensure = 'Present' |
| 72 | + ResetPeriodSeconds = $ResetPeriodSeconds |
| 73 | + RebootMessage = $RebootMessage |
| 74 | + FailureCommand = $FailureCommand |
| 75 | + FailureActionsOnNonCrashFailures = $FailureActionsOnNonCrashFailures |
| 76 | + FailureActionsCollection = @( |
| 77 | + DSC_xFailureAction |
| 78 | + { |
| 79 | + Type = 'RESTART' |
| 80 | + DelayMilliSeconds = 60000 |
| 81 | + } |
| 82 | + DSC_xFailureAction |
| 83 | + { |
| 84 | + Type = 'RESTART' |
| 85 | + DelayMilliSeconds = 120000 |
| 86 | + } |
| 87 | + DSC_xFailureAction |
| 88 | + { |
| 89 | + Type = 'Reboot' |
| 90 | + DelayMilliSeconds = 240000 |
| 91 | + } |
| 92 | + DSC_xFailureAction |
| 93 | + { |
| 94 | + Type = 'RUN_COMMAND' |
| 95 | + DelayMilliSeconds = 240000 |
| 96 | + } |
| 97 | + ) |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments