<< Back to Script Library

Cancel scheduled reboot

Cancel a reboot scheduled via the Schedule Reboot action by finding and deleting the scheduled task created by the Schedule Reboot action

Version: 1.5.13
Created: 2018-09-29
Modified: 2018-11-26
Creator: Guy Leech
Downloads: 55
Tags: Reboot Schedule
The Script Try this script with ControlUp Copy Script Copied to clipboard
#requires -version 3
<#
    Find and delete the scheduled task that the Scheduled Reboot SBA created

    @guyrleech 2018
#>

[string]$taskName = 'Reboot scheduled from ControlUp console'

[bool]$foundTask = $false
[int]$exitCode = 0

Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ForEach-Object `
{
    ## The Date property is empty so we get creation time from the task description
    [string]$createdAt = $null
    if( $_.Description -match '. Created at (.*)$' )
    {
        $createdAt = ", created at $($Matches[1])"
    }
    $_ | Unregister-ScheduledTask -Confirm:$false
    if( $? )
    {
        Write-Output "Successfuly deleted scheduled task `"$($_.TaskName)`"$createdAt"
    }
    else
    {
        Write-Error "Error deleting scheduled task `"$($_.TaskName)`"$createdAt"
        $exitCode = 1
    }
    $foundTask = $true
}

if( ! $foundTask )
{
    Write-Error "Failed to find a scheduled task called `"$taskName`""
}

Exit $exitCode
START YOUR TRIAL

Get Your Download Link

Gain access to ControlUp from your PC. Register and get a link to start your Free Trial.