PowerShell: Running PowerShell Scripts as Scheduled Task
To create a scheduled task do.
schtasks /CREATE /TN CheckHealthScript /TR "powershell.exe -noprofile -executionpolicy Unrestricted -file %public%\checkhealth.ps1" /IT /RL HIGHEST /SC DAILY
To get a list of scheduled tasks / enumerate scheduled tasks do:
schtasks /query
Links
Running PowerShell Scripts as Scheduled Task
About Scheduled Tasks on Technet
Script to enumerate / list scheduled tasks on a list of servers..
$Version="v8.4.28 Aaron Dodd"
$Description="Generate CSV of scheduled tasks in the environment"
#------------------------------------------------------------------------------
# Settings / Variables
#------------------------------------------------------------------------------
If (Test-Path "QueryScheduledTasks.config") {
$cfg=[xml](get-content "QueryScheduledTasks.config")
} Else {
Write-Host "!! ERROR !! - Config file not found"
Write-Host "A file with the same name as this script, ending in .config, must exist in the same directory as this script."
exit
}
$ServerList = Import-Csv $cfg.configuration.ServerList.name
$FinalReport=$cfg.configuration.FinalReport.name
$TempDir=$cfg.configuration.TempFolder.name
$TempReport=$TempDir + "\temp.csv"
$ErrorActionPreference=$cfg.configuration.ErrorAction.value
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Process tasks
#------------------------------------------------------------------------------
ForEach ($Server in $ServerList) {
schtasks /QUERY /S $Server.Name /FO CSV /V > $TempReport
$TempCsv += Import-Csv $TempReport
}
Remove-Item $TempReport
$TempCsv | Export-Csv $FinalReport -notype
#----------------------------------------------------------------
found here => http://blog.geekpoet.net/2008/04/powershell-script-to-report-on-all.html