Assets/Remove-OpsJob.ps1

<#
.SYNOPSIS
    Removes an existing Ops Job (Scheduled Task).
.DESCRIPTION
    Unregisters the Windows Scheduled Task associated with the given Job Name.
    Logs and history are left in place.
.PARAMETER JobName
    Name of the job to remove.
#>

param (
    [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
    [ValidateNotNullOrEmpty()]
    [string]$JobName
)

process {
    $TaskName = "OpsJob-$JobName"
    $ExistingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue

    if ($ExistingTask) {
        Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
        Write-Host "Removed OpsJob: $JobName"
    }
    else {
        Write-Warning "OpsJob '$JobName' not found."
    }
}