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.
Windows Server > Windows PowerShell
Comments
Post a Comment