# Homelab monitoring, Part 5: Home Assistant, Windows servers, Uptime Kuma, and a one-command rebuild # https://www.zadran.net/guides/homelab-monitoring-5-home-assistant-windows-setup-script # Generated from the guide, last updated 2026-10-13. # # NO WARRANTY. This script is provided as is. You are responsible for # understanding what it does before running it, and for the consequences. # Take a backup first. See https://www.zadran.net/disclaimer # # Destructive steps are left commented out on purpose -- uncomment them # only once you have understood what they do. # # If Windows will not run this file: a script saved from a browser is # marked as downloaded, and the RemoteSigned policy (the Windows Server # default) refuses it until you run Unblock-File .\homelab-monitoring-5-home-assistant-windows-setup-script.ps1 # Where the policy is Restricted (the Windows 10 and 11 default), run it as # powershell -ExecutionPolicy Bypass -File .\homelab-monitoring-5-home-assistant-windows-setup-script.ps1 # # These are the guide's PowerShell commands. Its bash commands are in # https://www.zadran.net/guides/homelab-monitoring-5-home-assistant-windows-setup-script/script.sh $ErrorActionPreference = 'Stop' # ---- Set these for your environment ---- # From Part 1 $MON_IP = '192.168.1.40' $monitor = "${MON_IP}" if (Get-Service NTDS -ErrorAction SilentlyContinue) { $role = 'Domain controller' $col = 'cpu,memory,logical_disk,physical_disk,net,os,system,service,time,ad,dns,dfsr' $svc = '(?i)^(ntds|dns|netlogon|kdc|w32time|dfsr)$' } elseif (Get-Service SMS_EXECUTIVE -ErrorAction SilentlyContinue) { $role = 'SCCM' $col = 'cpu,memory,logical_disk,physical_disk,net,os,system,service,time,mssql,iis' $svc = '(?i)^(sms_executive|sms_site_component_manager|mssqlserver|sqlserveragent|w3svc|wsusservice|w32time)$' } else { $role = 'Server' $col = 'cpu,memory,logical_disk,physical_disk,net,os,system,service,time' $svc = '(?i)^(w32time)$' } Write-Host "Detected role: $role" -ForegroundColor Cyan New-Item -ItemType Directory -Force C:\ProgramData\windows_exporter | Out-Null @" collectors: enabled: $col collector: service: include: "$svc" log: level: warn "@ | Set-Content -Encoding ascii C:\ProgramData\windows_exporter\config.yaml [Net.ServicePointManager]::SecurityProtocol = 'Tls12' $rel = Invoke-RestMethod https://api.github.com/repos/prometheus-community/windows_exporter/releases/latest $url = ($rel.assets | Where-Object name -like '*-amd64.msi').browser_download_url Invoke-WebRequest $url -OutFile "$env:TEMP\windows_exporter.msi" -UseBasicParsing Start-Process msiexec.exe -Wait -ArgumentList "/i `"$env:TEMP\windows_exporter.msi`" /qn ADDLOCAL=FirewallException REMOTE_ADDR=$monitor CONFIG_FILE=`"C:\ProgramData\windows_exporter\config.yaml`"" Start-Sleep 5 Get-Service windows_exporter | Format-Table Name, Status, StartType (Invoke-WebRequest http://localhost:9182/metrics -UseBasicParsing).Content -split "`n" | Select-String '^windows_service_state\{.*state="running"\} 1'