Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aev-mambro2/d4deaa62905b6b585e2c27ba260a87fa to your computer and use it in GitHub Desktop.
Save aev-mambro2/d4deaa62905b6b585e2c27ba260a87fa to your computer and use it in GitHub Desktop.
How to start a scheduled task on a remote microsoft windows server
<#
# Goal: to run a scheduled task on a remote windows server.
# Requirements: user must have CIM, WMI, and task admin privileges on the remote server.
# (c) 2021, A.E.Veltstra
#>
# Access the remote server. The computer name should be the short NETBUI name, without a domain.
$_session = New-CimSession -ComputerName "NETBUI NAME";
# Point to where the task is stored in the task scheduler. The opening \ points to what the
# Task Scheduler MSC interface names "Task Scheduler Library": the root.
$_path = "\Folder\Folder\Folder\Folder\";
# Specify the name of the scheduled task. It has no extension. Copy the name from the MSC if needed.
$_name = "Scheduled-Task-Name";
# Retrieve and start the task. If no error gets thrown, the task started successfully.
Get-ScheduledTask -CimSession $_session -TaskPath $_path -TaskName $_name | Start-ScheduledTask;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment