Public/Reset-SwJobEngine.ps1

Function Reset-SwJobEngine {
    <#
        .SYNOPSIS
        Reset job engine service on target machine
 
        .DESCRIPTION
        This function connects to target machine and restarts solarwinds job engine related services on target machine.
        This process helps to reset all schedule task for this service.
 
        Note: If -CleanDatabase switch is used, DB file on target machine will be removed in order to create new one.
    #>

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [string]$ServerName,

        [switch]$CleanDatabase
    )

    Process {
        Write-Verbose -Message ("Server {0}: restarting Services" -f $ServerName)
        if ($CleanDatabase.IsPresent) {
            Invoke-Command -ComputerName $ServerName -ScriptBlock {
                Stop-Service -Name SWJobEngineSvc2
                Stop-Service -Name SWCollectorService
                Start-Sleep -Seconds 3
                $files = Get-ChildItem -Path "C:\ProgramData\SolarWinds\JobEngine.v2\Data\" | Where-Object { ! $_.PSIsContainer }
                $files | Remove-Item -Force
                $files = Get-ChildItem -Path "C:\ProgramData\SolarWinds\Collector\Data" | Where-Object { ! $_.PSIsContainer }
                $files | Remove-Item -Force
                Start-Service -Name SWCollectorService
                Start-Sleep -Seconds 2
                Start-Service -Name SWJobEngineSvc2
            }
        }
        else {
            Invoke-Command -ComputerName $ServerName -ScriptBlock {
                Stop-Service -Name SWJobEngineSvc2
                Stop-Service -Name SWCollectorService
                Start-Sleep -Seconds 3
                Start-Service -Name SWCollectorService
                Start-Sleep -Seconds 2
                Start-Service -Name SWJobEngineSvc2
            }
        }
    }
}