Stop-RemoteComputerShutdown.ps1


Description

Purpose

Cancels a scheduled shutdown, restart, or hibernate operation on a remote computer.

Detailed Description

Wraps shutdown.exe /a to abort any pending shutdown, restart, or hibernate action on the target computer.

Back to Top

Usage

Example 1

Stop-RemoteComputerShutdown -ComputerName "SRV01"

Back to Top

Notes

Requires administrative privileges and remote access permissions.

Back to Top


Script

function Stop-RemoteComputerShutdown {
    <#
    .SYNOPSIS
    Cancels a scheduled shutdown, restart, or hibernate operation on a remote computer.

    .DESCRIPTION
    Wraps shutdown.exe /a to abort any pending shutdown, restart, or hibernate action on the target computer.

    .PARAMETER ComputerName
    The name of the remote computer to target.

    .EXAMPLE
    Stop-RemoteComputerShutdown -ComputerName "SRV01"

    .NOTES
    Requires administrative privileges and remote access permissions.
    #>
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param (
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$ComputerName
    )

    $cmd = "shutdown.exe /m \\$ComputerName /a"

    if ($PSCmdlet.ShouldProcess("Computer: $ComputerName", "Action: Cancel Scheduled Shutdown/Restart/Hibernate")) {
        try {
            Invoke-Command -ComputerName $ComputerName -ScriptBlock { param($command) & cmd /c $command } -ArgumentList $cmd -ErrorAction Stop
            Write-Output "Scheduled shutdown/restart/hibernate on $ComputerName has been canceled successfully."
        }
        catch {
            Write-Error "Failed to cancel the scheduled action on $ComputerName. Error: $($_.Exception.Message)"
            if ($_.Exception.InnerException) {
                Write-Error "Inner Exception: $($_.Exception.InnerException.Message)"
            }
        }
    }
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top