Friday, July 30, 2010

Powershell script to check scheduled tasks status

Function Get-ScheduledTask {



$tmpFile=Join-Path $env:temp "gsctmp.csv"

Write-Debug "Retrieving SCHTASKS.EXE for $computername"

$s=schtasks /query /s $computername /fo csv /v

if (-not $s)


Write-Debug "No connection to $computername"

Write-Warning ("Failed to find {0}" -f $computername.ToUpper())




if ($s -is [string])


Write-Debug "No scheduled tasks found for $computername"

Write-Warning ("{0} {1}" -f $computername.ToUpper(),$s)




Write-Debug "Sending data to $tmpFile"

$s[1..($s.count-1)] | Out-File $tmpFile -force

Write-Debug "Importing $tmpFile"

Import-Csv $tmpFile

Write-Debug "Deleting $tmpFile"

Remove-Item $tmpFile


get-content C:\PowerShellScripts\ScheduledTasks\serverlist.txt | foreach {get-scheduledtask $_ } | Select Hostname,Taskname,"Next Run Time","Last Run Time",Creator,"Run As User","Task To Run","Scheduled Task State","Scheduled Type",Schedule | Export-CSV C:\PowerShellScripts\ScheduledTasks\Report.CSV

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...