/
Update-RemoteTask.ps1
47 lines (36 loc) · 1.28 KB
/
Update-RemoteTask.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Author: Roberto Rodriguez (@Cyb3rWard0g)
# License: GPL-3.0
# References:
function Update-RemoteTask {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$ComputerName,
[Parameter(Mandatory=$false)]
[string]$FolderName,
[Parameter(Mandatory=$false)]
[string]$TaskName,
[Parameter(Mandatory=$false)]
[string]$Executable,
[Parameter(Mandatory=$false)]
[string]$Arguments
)
# connect to Task Scheduler:
$service = New-Object -ComObject Schedule.Service
$service.Connect($ComputerName)
# Get task folder that contains tasks:
$folder = $service.GetFolder($FolderName)
# Enumerate Specific Task
$task = $folder.GetTask($TaskName)
# get task definition and change it (i.e Arguments)
$taskdefinition = $task.Definition
$taskdefinition.Actions | ForEach-Object {$_.Path = $Executable}
$taskdefinition.Actions | ForEach-Object {$_.Arguments = $Arguments}
# Flags:
# 4 = UPDATE
# 6 = CREATE_UPDATE
#
# LogonType:
# 5 = Indicates that a Local System, Local Service, or Network Service account is being used as a security context to run the task.
$folder.RegisterTaskDefinition($task.Name, $taskdefinition, 4, "System", $null, 5)
}