The following Powershell functions allow you to manage querying, creating and removing scheduled tasks on one or more computers remotely.
The functions use schtasks.exe, which is included in Windows. Unlike the Win32_ScheduledJob WMI class, the schtasks.exe commandline tool will show manually created tasks, as well as script-created ones. The examples show some, but not all parameters in action. I think the parameter names are descriptive enough to figure it out, really. If not, take a look at schtasks.exe /?. One tip: try piping a list of computer names to foreach-object and into this function.


Function Get-ScheduledTask
	param([string]$ComputerName = "localhost")
	Write-Host "Computer: $ComputerName"
	$Command = "schtasks.exe /query /s $ComputerName"
	Invoke-Expression $Command
	Clear-Variable Command -ErrorAction SilentlyContinue
	Write-Host "`n"
# EXAMPLE: Get-ScheduledTask -ComputerName Server01
Function Remove-ScheduledTask
	[string]$ComputerName = "localhost",
	[string]$TaskName = "blank"
	If ((Get-ScheduledTask -ComputerName $ComputerName) -match $TaskName)
		If ((Read-Host "Are you sure you want to remove task $TaskName from $ComputerName(y/n)") -eq "y")
			$Command = "schtasks.exe /delete /s $ComputerName /tn $TaskName /F"
			Invoke-Expression $Command
			Clear-Variable Command -ErrorAction SilentlyContinue
		Write-Warning "Task $TaskName not found on $ComputerName"
# EXAMPLE: Remove-ScheduledTask -ComputerName Server01 -TaskName MyTask
Function Create-ScheduledTask
	[string]$ComputerName = "localhost",
	[string]$RunAsUser = "System",
	[string]$TaskName = "MyTask",
	[string]$TaskRun = '"C:\Program Files\Scripts\Script.vbs"',
	[string]$Schedule = "Monthly",
	[string]$Modifier = "second",
	[string]$Days = "SUN",
	[string]$Months = '"MAR,JUN,SEP,DEC"',
	[string]$StartTime = "13:00",
	[string]$EndTime = "17:00",
	[string]$Interval = "60"	
	Write-Host "Computer: $ComputerName"
	$Command = "schtasks.exe /create /s $ComputerName /ru $RunAsUser /tn $TaskName /tr $TaskRun /sc $Schedule /mo $Modifier /d $Days /m $Months /st $StartTime /et $EndTime /ri $Interval /F"
	Invoke-Expression $Command
	Clear-Variable Command -ErrorAction SilentlyContinue
	Write-Host "`n"
# EXAMPLE: Create-ScheduledTask -ComputerName MyServer -TaskName MyTask02 -TaskRun "D:\scripts\script2.vbs"


Tagged with:

14 Responses to Managing Scheduled Tasks Remotely Using Powershell

  1. Getting Scheduled Tasks in Powershell « PowerShell Station says:

    […] Another take on scripting SCHTASKS.EXE Leave a Comment […]

  2. Mariusz says:


  3. Woody says:

    Invoke-Expression is unnecessary. You can simply state
    schtasks.exe /query /s $ComputerName

  4. Patrick Parkison says:

    This worked great. It worked with no issues. Thanks.

  5. […] Managing Scheduled Tasks Remotely Using Powershell | PeetersOnline – […]

  6. Axel Andersen says:

    This was very helpfull. I added a filter, that converts the returned data to objects:
    filter ConvertFrom-CmdList {

    $_ | foreach {if ($_ -match ‘^$’){ $newobj = New-Object Object
    $obj | foreach {$newobj | Add-Member NoteProperty $($_ -split ‘:’)[0] “$($_ -replace ‘^.*:[ ]+’)”}
    $obj = @()}
    if ($_ -notmatch ‘^$’){$obj += $_ }

    Function Get-ScheduledTask {

    param([string]$ComputerName = “localhost”)
    Write-Host “Computer: $ComputerName”
    schtasks.exe /query /s $ComputerName /FO List | ConvertFrom-CmdList

  7. Tom Purl says:

    Great tip. Thanks!

  8. cooper wu says:

    very useful.

  9. cooper wu says:

    thanks very much.

  10. Josh Cook says:

    If you want prettier output from schtasks /query, you can easily convert it to an object:

    $Tasks = schtasks.exe /QUERY /V /FO:CSV /S:$ComputerName | ConvertFrom-Csv

    /V Gives you much more info
    /FO:CSV formats the output into csv so you can convert it right into an array of task objects. I tend to throw in a where statement too to get rid of the artifacts and built in tasks.

    $Tasks = schtasks.exe /QUERY /V /FO:CSV /S:$ComputerName | ConvertFrom-Csv | Where-object {$_.taskName -notlike '\Windows*' -and $_.taskname -notlike 'taskname'}

  11. pGwtech says:

    Thank you.

  12. Jitendra says:

    I would like to know who invoked the scheduled task.

    I user one PS script to invoke an already configured scheduled task that is set to run with high privileges. As part of its execution, the scheduled tasks writes output to htmm file. Is there anyway we can get who has invoked the scheduled task using the firs PS script. I would like to add their name to the output of the scheduled task script.

  13. Félix says:

    Hi, I would love to use the script but I’m rookie in PowerShell subject. How should I invoke the functions?

  14. Abhijeet says:

    Hi, I am migrating schedule task from windows server 2003 to windows server 2008. One way is from Task scheduler GUI using export from and import to technique and then edit the arguments in Action. I am interested in knowing how to do it using a powershell script for automation using PS version 2.0. The version 3.0 has the cmdlets but i am not thinking of using it.

Leave a Reply