Public/ps1/Files/Stop-ApprxrFileWatcherLocation.ps1

<#
    .SYNOPSIS
    Stops all running watcher jobs for a given Apprxr file watcher location.
 
    .DESCRIPTION
    Finds and stops all background jobs associated with the specified file watcher location name, and logs the action. Used for cleanup and management of watcher jobs.
 
    .PARAMETER Name
    The unique name for the location whose watcher jobs should be stopped.
 
    .EXAMPLE
    Stop-ApprxrFileWatcherLocation -Name 'Location1'
    Stops all watcher jobs for 'Location1'.
 
    .NOTES
    This function is part of the Apprxr file watcher management system.
#>

function Stop-ApprxrFileWatcherLocation {
    param(
        [Parameter(Mandatory)]
        [string]$Name
    )
    $jobs = Get-Job | Where-Object { $_.Name -like "Apprxr$Name*" }
    foreach ($job in $jobs) {
        try {
            Stop-Job $job -ErrorAction SilentlyContinue
            Remove-Job $job -ErrorAction SilentlyContinue
            Log "Stopped watcher job: $($job.Name) for location: $Name"
        } catch {
            Log "Failed to stop watcher job: $($job.Name) for location: $Name. Error: $_"
        }
    }
}