-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemove-ExpiredScheduledRestartComputerJob.ps1
51 lines (45 loc) · 1.52 KB
/
Remove-ExpiredScheduledRestartComputerJob.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
.Synopsis
Clean up expired Scheduled Restart-Computer jobs and scripts.
.DESCRIPTION
Clean up expired Scheduled Restart-Computer jobs and scripts.
.PARAMETER JobNamePrefix
The prefix of the scheduled restart computer job exists to differentiate
the restart jobs from other PowerShell scheduled jobs.
.PARAMETER ScriptFilePath
The path to the script file that is executed by the scheduled restart computer
job.
.NOTES
Created by: Jason Wasser @wasserja
Modified: 6/2/2017
.EXAMPLE
Remove-ExpiredScheduledRestartComputerJob
.EXAMPLE
Remove-ExpiredScheduledRestartComputerJob -JobNamePrefix 'RestartComputerJob' -ScriptFilePath 'C:\Scripts'
#>
#Requires -RunAsAdministrator
#Requires -Modules PSScheduledJob
function Remove-ExpiredScheduledRestartComputerJob
{
[CmdletBinding(SupportsShouldProcess=$True)]
Param
(
[string]$JobNamePrefix = 'RestartComputer-',
[ValidateScript({ Test-Path $_ -PathType Container })]
[string]$ScriptFilePath="C:\Temp\"
)
Begin
{
}
Process
{
Write-Verbose -Message 'Performing cleanup of any existing expired Restart Jobs.'
$ExpiredRestartJobs = Get-ScheduledRestartComputerJob | Where-Object -FilterScript {$_.JobStatus -ne 'Running' -and $_.IsJobExpired}
foreach ($RestartJob in $ExpiredRestartJobs) {
Remove-ScheduledRestartComputerJob -Name $RestartJob.Name -WhatIf:$PSBoundParameters.ContainsKey('WhatIf')
}
}
End
{
}
}