Home > database >  Combine two Powershell results for sheduled tasks
Combine two Powershell results for sheduled tasks

Time:07-14

this gives a nice table of not successfull sheduled tasks.

Get-ScheduledTask | Where State -ne "Disabled" | Get-ScheduledTaskInfo |Where taskpath -EQ "\" | Where LastTaskResult -GT 1 
| FT TaskPath,TaskName,LastRunTime, LastTaskResult,NextRunTime,NumberofMissedRuns

and this gives a nice table with execution paths.

( Get-ScheduledTask ).Actions | FT Execute,Arguments

Is there a way to get one combined table with all the desired reults ?

It's PowerShell 5.1

CodePudding user response:

Here is one way to do it:

Get-ScheduledTask | Where-Object State -ne "Disabled" | 
    ForEach-Object {
        Get-ScheduledTaskInfo -InputObject $_ | 
            Where-Object {$_.TaskPath -EQ "\" -and $_.LastTaskResult -GT 1}
            Select-Object TaskPath, TaskName, LastRunTime, LastTaskResult, NextRunTime, NumberofMissedRuns |
            Add-Member -MemberType NoteProperty -Name Execute -Value $_.Actions.Execute -PassThru |
            Add-Member -MemberType NoteProperty -Name Arguments -Value $_.Actions.Arguments -PassThru
    } | Format-Table -AutoSize

I noticed that the table was now too wide to display properly on my test system, so you may want to use Format-List instead.

  • Related