Stop-ScheduledScript.ps1
19 Sep 2025Description
Purpose
Stops a scheduled task by its name.
Detailed Description
The Stop-ScheduledScript function stops a scheduled task by its name. It first checks if the task exists using the Get-ScheduledTask cmdlet, and if found, stops the task using the Stop-ScheduledTask cmdlet.
Usage
Example 1
Stop-ScheduledScript -TaskName "MyTask"
Stops the scheduled task named “MyTask”.
Notes
Author: Your Name Date: Current Date
Script
<#
.SYNOPSIS
Stops a scheduled task by its name.
.DESCRIPTION
The Stop-ScheduledScript function stops a scheduled task by its name. It first checks if the task exists using the Get-ScheduledTask cmdlet, and if found, stops the task using the Stop-ScheduledTask cmdlet.
.PARAMETER TaskName
Specifies the name of the scheduled task to stop.
.EXAMPLE
Stop-ScheduledScript -TaskName "MyTask"
Stops the scheduled task named "MyTask".
.INPUTS
System.String
.OUTPUTS
None
.NOTES
Author: Your Name
Date: Current Date
#>
function Stop-ScheduledScript {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$TaskName
)
if ($PSCmdlet.ShouldProcess("$TaskName", "Stop scheduled task")) {
try {
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
Stop-ScheduledTask -TaskName $TaskName
}
else {
Write-Error "No scheduled task found with the name $TaskName"
}
}
catch {
Write-Error "Failed to stop scheduled task: $_"
}
}
}
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.