Set-StrictMode -Version Latest . "$PSScriptRoot\helpers.ps1" $Settings = Import-Settings $taskName = $Settings.ScheduledTaskName $scriptPath = Join-Path $PSScriptRoot "watch-downloads.ps1" $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$scriptPath`"" $trigger = New-ScheduledTaskTrigger -AtLogOn $principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel LeastPrivilege $settingsObj = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -MultipleInstances IgnoreNew Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settingsObj -Force | Out-Null Write-Log "Installed scheduled task: $taskName" Write-Host "Installed scheduled task: $taskName" Write-Host "It will start at next logon. To start now, run:" Write-Host "powershell -ExecutionPolicy Bypass -File .\scripts\watch-downloads.ps1"