-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreate-Windows-Task.ps1
More file actions
49 lines (35 loc) · 1.72 KB
/
Create-Windows-Task.ps1
File metadata and controls
49 lines (35 loc) · 1.72 KB
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
48
function Create-Windows-Task-That-Runs-Every-15-Minutes {
param($name, $program, $programArguments, $username, $password)
$service = New-Object -ComObject "Schedule.Service"
$service.Connect($ENV:ComputerName)
$rootFolder = $service.GetFolder("\")
$taskDefinition = $service.NewTask(0)
$trigger = $taskDefinition.Triggers.Create(2)
$trigger.StartBoundary = (Get-Date 00:00AM).AddDays(1) | Get-Date -Format yyyy-MM-ddTHH:ss:ms
$trigger.DaysInterval = 1
$repetition = $trigger.Repetition
$repetition.Duration = "P1D"
$repetition.Interval = "PT15M"
$action = $taskDefinition.Actions.Create(0)
$action.Path = $program
$action.Arguments = $programArguments
$principal = $taskDefinition.Principal
$principal.RunLevel = 0 # 0=normal, 1=Highest Privileges
$rootFolder.RegisterTaskDefinition($name, $taskDefinition, 6, $username, $password, 1)
}
function Create-Windows-Task-That-Runs-Every-Midnight {
param($name, $program, $programArguments, $username, $password)
$service = New-Object -ComObject "Schedule.Service"
$service.Connect($ENV:ComputerName)
$rootFolder = $service.GetFolder("\")
$taskDefinition = $service.NewTask(0)
$trigger = $taskDefinition.Triggers.Create(2)
$trigger.StartBoundary = (Get-Date 00:00AM).AddDays(1) | Get-Date -Format yyyy-MM-ddTHH:ss:ms
$trigger.DaysInterval = 1
$action = $taskDefinition.Actions.Create(0)
$action.Path = $program
$action.Arguments = $programArguments
$principal = $taskDefinition.Principal
$principal.RunLevel = 0 # 0=normal, 1=Highest Privileges
$rootFolder.RegisterTaskDefinition($name, $taskDefinition, 6, $username, $password, 1)
}