Newer
Older
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
49
50
51
52
53
$InstallDir = "C:\Tools\AutoTx-Updater"
$JobScript = "Update-Service.ps1"
$Config = "UpdaterConfig.inc.ps1"
if (Test-Path $InstallDir) {
Write-Host "ERROR: updater directory already existing, stopping installer!"
Write-Host "[$($InstallDir)]"
Exit
}
if (-Not (Test-Path $Config)) {
Write-Host "ERROR: no config file for the updater found!"
Write-Host "[$($Config)]"
Exit
}
New-Item -Force -Type Directory $InstallDir
Copy-Item $JobScript $InstallDir
Copy-Item $Config $InstallDir
# create a repetition interval
$TimeSpan = New-TimeSpan -Minutes 10
# configure a JobTrigger for the task using the repetition interval from above,
# repeating forever
$JobTrigger = New-JobTrigger `
-Once `
-At (Get-Date).Date `
-RepetitionInterval $TimeSpan `
-RepeatIndefinitely
# configure the JobOptions for the task (battery options should not be required
# on a fixed system, but doesn't hurt either)
$JobOptions = New-ScheduledJobOption `
-RunElevated `
-StartIfOnBattery `
-ContinueIfGoingOnBattery
# set credentials for running the task (requires permission to start/stop the
# service and overwriting the configuration and binaries)
$Cred = Get-Credential
# register the job for execution
Register-ScheduledJob `
-Name "AutoTx-Updater" `
-FilePath "$($InstallDir)\$($JobScript)" `
-ArgumentList "$($InstallDir)\$($Config)" `
-ScheduledJobOption $JobOptions `
-Trigger $JobTrigger `
-Credential $Cred `
-Verbose