To do what you're wanting you'll need to build a custom object, and fill the object with the details from the schtasks output. This will give you the ability to do what you're looking for. I did a project at work for this some time back. I'll have access to that code Sunday, and will post it up then.
Here's the Scheduled Task query Script I built, since it was one of my first scripts, it's not very pretty but it should have all the information you need:
function query_tasks
{
if ($args -eq '/?')
{
Write-Output "Usage: query_tasks ComputerName taskname"
Write-Output "Task name defaults to wildcard search and can be multiple words."
Write-Output "Computer name, and task names must be included."
}
elseif ($args.length -lt 2)
{
Write-Output "Error: Must include computer name and partial task name to search for."
}
else
{
$CompName = $args[0]
$Tasks = $args[1..($args.length-1)]
$arrTasks = $(schtasks /query /v /fo csv /s $CompName)
$taskName = "`"*$Tasks*`""
$arrTask = $arrTasks -like $taskName -split '","'
$arrSchTasksAttributes = @( )
$arrSchTasksAttributes += "HostName"
$arrSchTasksAttributes += "TaskName"
$arrSchTasksAttributes += "NextRunTime"
$arrSchTasksAttributes += "Status"
$arrSchTasksAttributes += "LastRunTime"
$arrSchTasksAttributes += "LastResult"
$arrSchTasksAttributes += "Creator"
$arrSchTasksAttributes += "Schedule"
$arrSchTasksAttributes += "TaskToRun"
$arrSchTasksAttributes += "StartIn"
$arrSchTasksAttributes += "Comment"
$arrSchTasksAttributes += "ScheduledTaskState"
$arrSchTasksAttributes += "ScheduledType"
$arrSchTasksAttributes += "StartTime"
$arrSchTasksAttributes += "StartDate"
$arrSchTasksAttributes += "EndDate"
$arrSchTasksAttributes += "Days"
$arrSchTasksAttributes += "Months"
$arrSchTasksAttributes += "RunAsUser"
$arrSchTasksAttributes += "DeleteTaskIfNotRescheduled"
$arrSchTasksAttributes += "StopTaskIfRunsXHoursandXMins"
$arrSchTasksAttributes += "Repeat_Every"
$arrSchTasksAttributes += "Repeat_Until_Time"
$arrSchTasksAttributes += "Repeat_Until_Duration"
$arrSchTasksAttributes += "Repeat_StopIfStillRunning"
$arrSchTasksAttributes += "IdleTime"
$arrSchTasksAttributes += "PowerManagement"
$arrTaskObj = $null
$arrTaskObj = New-Object psobject
for ($t = 0; $t -lt $arrTask.length; $t++)
{
Add-Member -InputObject $arrTaskObj -MemberType NoteProperty `
-Name $arrSchTasksAttributes[$t] -Value $arrTask[$t]
}
$listHeaders = @{Expression={$_.HostName};Label="Host Name"}, @{Expression={$_.TaskName};Label="Task Name"}, @{Expression={$_.NextRunTime};Label="Next Run Time"}, @{Expression={$_.LastRunTime};Label="Last Run Time"}, @{Expression={$_.LastResult};Label="Last Result"}, @{Expression={$_.Status};Label="Current Status"}
$arrTaskObj | Format-List $listHeaders
}
}
It essentially queries the server for the entire scheduled task list and receives the output as an array. It then searches the output for the line that contains the specific scheduled task. Once that is found, it generates an array of the searched tasks line of data (which has no header information at this point). Then using the header information that scheduled task returns as an array, it builds a custom object with each piece of header information as a property that is then filled with the data from the specific task's array.
Because of the way that the object is created, you could probably tweak this script to allow for the inclusion of multiple scheduled tasks. As it stands, the output is filtered through the $listHeaders variable, but you could strike that and just output the $arrTaskObj object to the pipe which would allow you to call and access the properties for.