Public/Test-TaskSequence.ps1

function Test-TaskSequence
{
    <#
        .DESCRIPTION
            Check if a Configuration Manager task sequence is currently running
    
        .EXAMPLE
            $TaskSequence = Test-TaskSequence
    
        .NOTES
            Created by: Jon Anderson
            Modified: 2023-07-03
    #>

    try
    {    
        $TSEnvironment = New-Object -ComObject Microsoft.SMS.TSEnvironment
    }
    catch {}
    if($null -eq $TSEnvironment)
    {
        return $false
    }
    else
    {
        try
        {
            $SMSTSType = $TSEnvironment.Value("_SMSTSType")
        }
        catch{}
        if($null -eq $SMSTSType)
        {
            return $false
        }
        else
        {
            return $true
        }
    }
}