PowerShell: Running PowerShell Scripts as Scheduled Task

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Schtasks.exe – Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote computer. Running Schtasks.exe without arguments displays the status and next run time for each registered task.

If you have jobs that need to execute regularly, you can manage them with a PowerShell script and make it a scheduled task:

Logo_PowerShell

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 MSDN

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.