Start-ScheduledScript.ps1


Description

Purpose

Starts a scheduled task by its name.

Detailed Description

The Start-ScheduledScript function starts a scheduled task by its name. It checks if the task exists and then starts it.

Back to Top

Usage

Example 1

Start-ScheduledScript -TaskName "MyTask"

This example starts the scheduled task named “MyTask”.

Back to Top

Notes

No additional notes.

Back to Top


Script

<#
.SYNOPSIS
Starts a scheduled task by its name.

.DESCRIPTION
The Start-ScheduledScript function starts a scheduled task by its name. It checks if the task exists and then starts it.

.PARAMETER TaskName
The name of the scheduled task to start.

.EXAMPLE
Start-ScheduledScript -TaskName "MyTask"

This example starts the scheduled task named "MyTask".

#>
function Start-ScheduledScript {
    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string]
        $TaskName
    )

    if ($PSCmdlet.ShouldProcess("$TaskName", "Start scheduled task")) {
        try {
            if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
                Start-ScheduledTask -TaskName $TaskName
            }
            else {
                Write-Error "No scheduled task found with the name $TaskName"
            }
        }
        catch {
            Write-Error "Failed to start scheduled task: $_"
        }
    }
}

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