Powershell: Run a Scheduled Task Remotely

Scenario:  You want to run a Scheduled Task remotely without needing to remote into the server, open task scheduler, and execute the task.

Solution:  Run the following in Powershell with appropriate permissions:

schtasks /run /s exchsvr1 /tn "exchange monitor"

If you want to loop it so it runs manually every 30 minutes, run the following:

#When the counter reaches 30, that’s 15 hours

$counter  = 0

Do{
schtasks /run /s exchsvr1 /tn "exchange monitor"
sleep 1800
$counter++
“$counter – Running script”
} While ($counter –lt 30)

 

Leave a comment