Last active
March 11, 2021 20:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
# 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