Skip to content

Instantly share code, notes, and snippets.

@asheroto
Last active April 9, 2026 03:05
Show Gist options
  • Select an option

  • Save asheroto/c57ec507921531acd4f7ee0550ea7e87 to your computer and use it in GitHub Desktop.

Select an option

Save asheroto/c57ec507921531acd4f7ee0550ea7e87 to your computer and use it in GitHub Desktop.
Automatically Start UniFi OS Server on Boot on Windows

Automatically Start UniFi OS Server on Boot (Windows)

You must run UniFi OS Server using the account you initially set it up on. This is a Windows-specific limitation. On Linux/Docker, UniFi OS Server runs as a system service and does not have this constraint. If you would rather use a service account on Windows, create a service account then install UniFi OS Server under it.

Prerequisites

  • Run this script as an Administrator
  • UniFi OS Server must already be installed and working when launched manually

Usage

  1. Run the script in an elevated PowerShell session. It will prompt for credentials.
  2. The password is stored encrypted by Windows Task Scheduler and is not saved in plaintext

What it does Registers a scheduled task that launches UniFi OS Server 30 seconds after boot under the specified user account. The delay gives Windows time to finish initializing before the server starts. If the task already exists, it is removed and re-created.

Note: Running under the SYSTEM account will launch the process but UniFi OS Server will not function correctly. It requires the user context it was configured in.

# ===== CONFIG =====
$ExePath = "C:\Program Files\UniFi OS Server\UniFi OS Server.exe"
$TaskName = "UniFi OS Server"
# ===== PROMPT FOR CREDENTIALS =====
$Cred = Get-Credential -Message "Enter the credentials for the account UniFi OS Server was installed under"
# ===== ACTION =====
$Action = New-ScheduledTaskAction `
-Execute $ExePath
# ===== TRIGGER =====
$Trigger = New-ScheduledTaskTrigger -AtStartup
$Trigger.Delay = "PT30S"
# ===== SETTINGS =====
$Settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable
# ===== REGISTER =====
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
}
Register-ScheduledTask `
-TaskName $TaskName `
-Action $Action `
-Trigger $Trigger `
-Settings $Settings `
-User $Cred.UserName `
-Password ($Cred.GetNetworkCredential().Password) `
-RunLevel Highest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment