Status of Scheduled Task


hi all,

i investigating if possible powershell check multiple windows xp client machines scheduled task , if status "could not run" should run commands.

i able run following command:

schtasks.exe /query /s hostname

but shows scheduled tasks , status.

once able confirm status of specific scheduled task "could not run", script should run commands , store text or log file in c:\temp.

any guidance or appreciated.

powershell newbie.

-steve

hi steve,

thanks posting.

the script below may helpful you, can save d:\taskscheduled.ps1 locally, use invoke-command remote run script powershell2.0.

i assume status "could not run" "disabled", if have misunderstanding, please refer state below change value of "1" in cmdlet "where {$_.state -like "1"}":

0  state = 'unknown'
1  state = 'disabled'
2  state = 'queued'
3  state = 'ready'
4  state = 'running'

d:\taskscheduled.ps1:

function gettasks($path) {     $out = @()      # root tasks     $schedule.getfolder($path).gettasks(0) | % {         $out += new-object psobject -property @{             "name" = $_.name             "path" = $_.path             "state" = $_.state            }     }      # tasks subfolders     $schedule.getfolder($path).getfolders(0) | % {         $out += gettasks($_.path)     }      #output     $out }  $tasks = @()  $schedule = new-object -comobject "schedule.service" $schedule.connect()   # start inventory $tasks += gettasks("\")  # close com [system.runtime.interopservices.marshal]::releasecomobject($schedule) | out-null remove-variable schedule  # output tasks $tasks | {$_.state -like "1"} | ft

then can run script below run script above in remote computer:

invoke-command -computername remotecomputer -filepath d:\taskscheduled.ps1

hope helps.


we trying better understand customer views on social support experience, participation in interview project appreciated if have time.
helping make community forums great place.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...