Skip to content

Instantly share code, notes, and snippets.

@tkouba
Created May 9, 2022 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkouba/67ddabe4cf2f84d08092ad5166c2cd1f to your computer and use it in GitHub Desktop.
Save tkouba/67ddabe4cf2f84d08092ad5166c2cd1f to your computer and use it in GitHub Desktop.
Add Powershell scheduled job for stopping services on cluster passive node
$options = New-ScheduledJobOption -WakeToRun -StartIfIdle -MultipleInstancePolicy IgnoreNew -RunElevated
$trigger = New-JobTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5) -RepeatIndefinitely
Unregister-ScheduledJob -Name "Stop-ClusterServices" -ErrorAction SilentlyContinue
Register-ScheduledJob -Name "Stop-ClusterServices" -ScriptBlock {
(Get-ClusterGroup | Where-Object {$_.OwnerNode -ne $env:COMPUTERNAME} | Get-ClusterResource) | Where-Object {$_.ResourceType -eq 'Generic Service'} | Get-Service | Where-Object {$_.Status -eq 'Running'} | Stop-Service -Verbose
} -Trigger $trigger -ScheduledJobOption $options
(Get-ScheduledJob -Name "Stop-ClusterServices").StartJob()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment