Public/Get-pseScheduledTask.ps1

Function Get-pseScheduledTask {
<#
.SYNOPSIS
    Get the scheduled task information.
 
.DESCRIPTION
    Get the scheduled task information.
 
.PARAMETER TaskName
    The name of the task to get information about.
 
.EXAMPLE
    Get-pseScheduledTask -TaskName 'MicrosoftEdgeUpdateTaskMachineCore1'
 
    TaskName TaskPath TaskState
    -------- -------- ---------
    MicrosoftEdgeUpdateTaskMachineCore1 \Microsoft\Windows\WindowsUpdate Ready
#>


    [cmdletbinding()]
    Param (
        [parameter (mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string[]]$TaskName
    )

    Begin {}

    Process {
        foreach ($task in $taskname) {
            try {
                $result = Get-ScheduledTask -TaskName $Task -ea stop

                [pscustomobject]@{
                    TaskName  = $result.taskname
                    TaskPath  = $result.taskPath
                    TaskState = $result.state
                }
            } catch {
                Write-Error "The task $Task does not exist. $_"
            }
        }
    }
}