46 lines
1.1 KiB
PowerShell
46 lines
1.1 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$ExecutablePath,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$WorkingDirectory
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$taskName = 'Inventera Server'
|
|
|
|
if (-not (Split-Path -Parent $ExecutablePath)) {
|
|
throw 'The Inventera executable path is invalid.'
|
|
}
|
|
|
|
$action = New-ScheduledTaskAction `
|
|
-Execute $ExecutablePath `
|
|
-WorkingDirectory $WorkingDirectory
|
|
|
|
$trigger = New-ScheduledTaskTrigger -AtStartup
|
|
|
|
$settings = New-ScheduledTaskSettingsSet `
|
|
-StartWhenAvailable `
|
|
-RestartCount 5 `
|
|
-RestartInterval (New-TimeSpan -Minutes 1) `
|
|
-ExecutionTimeLimit ([TimeSpan]::Zero) `
|
|
-MultipleInstances IgnoreNew
|
|
|
|
$principal = New-ScheduledTaskPrincipal `
|
|
-UserId 'SYSTEM' `
|
|
-LogonType ServiceAccount `
|
|
-RunLevel Highest
|
|
|
|
$task = New-ScheduledTask `
|
|
-Action $action `
|
|
-Trigger $trigger `
|
|
-Settings $settings `
|
|
-Principal $principal `
|
|
-Description 'Starts the Inventera web server when Windows starts.'
|
|
|
|
Register-ScheduledTask `
|
|
-TaskName $taskName `
|
|
-InputObject $task `
|
|
-Force | Out-Null
|