|
| 1 | +--- |
| 2 | +title: Windows Service |
| 3 | +description: Run the MS Teams Observability collector as a Windows Scheduled Task — XML import or PowerShell setup, with boot trigger and configuration steps. |
| 4 | +sidebar: |
| 5 | + label: Service (Windows) |
| 6 | + order: 9 |
| 7 | +--- |
| 8 | + |
| 9 | +import { Tabs, TabItem, Aside } from '@astrojs/starlight/components'; |
| 10 | + |
| 11 | +On Windows, the collector runs as a **Scheduled Task** triggered at system startup. This page provides two setup methods: importing an XML task definition, or creating the task via PowerShell. |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- Collector binary (`ms-teams-agent.exe`) placed in a permanent directory (e.g., `C:\Program Files\Phenisys\`) |
| 16 | +- A valid `config.yaml` in the same directory |
| 17 | +- Administrator privileges on the Windows host |
| 18 | +- The service account must have **Log on as a batch job** rights |
| 19 | + |
| 20 | +## Method 1: Import XML Task Definition |
| 21 | + |
| 22 | +Save the following XML as `MSTeamsObservabilityAgent.xml`, update the paths and user, then import. |
| 23 | + |
| 24 | +<Tabs> |
| 25 | + <TabItem label="XML Template"> |
| 26 | +```xml |
| 27 | +<?xml version="1.0" encoding="UTF-16"?> |
| 28 | +<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> |
| 29 | + <RegistrationInfo> |
| 30 | + <Author>YOURDOMAIN\youruser</Author> |
| 31 | + <URI>\MSTeamsObservabilityAgent</URI> |
| 32 | + </RegistrationInfo> |
| 33 | + <Triggers> |
| 34 | + <BootTrigger> |
| 35 | + <Enabled>true</Enabled> |
| 36 | + </BootTrigger> |
| 37 | + </Triggers> |
| 38 | + <Principals> |
| 39 | + <Principal id="Author"> |
| 40 | + <UserId>YOURDOMAIN\youruser</UserId> |
| 41 | + <LogonType>Password</LogonType> |
| 42 | + <RunLevel>HighestAvailable</RunLevel> |
| 43 | + </Principal> |
| 44 | + </Principals> |
| 45 | + <Settings> |
| 46 | + <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> |
| 47 | + <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> |
| 48 | + <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> |
| 49 | + <AllowHardTerminate>true</AllowHardTerminate> |
| 50 | + <StartWhenAvailable>false</StartWhenAvailable> |
| 51 | + <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> |
| 52 | + <IdleSettings> |
| 53 | + <StopOnIdleEnd>true</StopOnIdleEnd> |
| 54 | + <RestartOnIdle>false</RestartOnIdle> |
| 55 | + </IdleSettings> |
| 56 | + <AllowStartOnDemand>true</AllowStartOnDemand> |
| 57 | + <Enabled>true</Enabled> |
| 58 | + <Hidden>false</Hidden> |
| 59 | + <RunOnlyIfIdle>false</RunOnlyIfIdle> |
| 60 | + <WakeToRun>false</WakeToRun> |
| 61 | + <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> |
| 62 | + <Priority>7</Priority> |
| 63 | + </Settings> |
| 64 | + <Actions Context="Author"> |
| 65 | + <Exec> |
| 66 | + <Command>"C:\Program Files\Phenisys\ms-teams-agent.exe"</Command> |
| 67 | + <Arguments>run --config "C:\Program Files\Phenisys\config.yaml"</Arguments> |
| 68 | + <WorkingDirectory>C:\Program Files\Phenisys</WorkingDirectory> |
| 69 | + </Exec> |
| 70 | + </Actions> |
| 71 | +</Task> |
| 72 | +``` |
| 73 | + </TabItem> |
| 74 | +</Tabs> |
| 75 | + |
| 76 | +### Import the task |
| 77 | + |
| 78 | +1. Update the XML: |
| 79 | + - Replace `YOURDOMAIN\youruser` with your service account |
| 80 | + - Replace paths under `<Command>`, `<Arguments>`, and `<WorkingDirectory>` with your installation path |
| 81 | +2. Open **Task Scheduler** (`taskschd.msc`) |
| 82 | +3. Click **Import Task…** in the right sidebar |
| 83 | +4. Select your XML file |
| 84 | +5. Enter the password for the service account when prompted |
| 85 | + |
| 86 | +## Method 2: PowerShell |
| 87 | + |
| 88 | +Run the following in an elevated PowerShell session: |
| 89 | + |
| 90 | +```powershell |
| 91 | +$User = "YOURDOMAIN\youruser" |
| 92 | +$Credential = Get-Credential -UserName $User -Message "Enter your password" |
| 93 | +$PlainPassword = $Credential.GetNetworkCredential().Password |
| 94 | +
|
| 95 | +$Action = New-ScheduledTaskAction ` |
| 96 | + -Execute "C:\Program Files\Phenisys\ms-teams-agent.exe" ` |
| 97 | + -Argument 'run --config "C:\Program Files\Phenisys\config.yaml"' |
| 98 | +
|
| 99 | +$Trigger = New-ScheduledTaskTrigger -AtStartup |
| 100 | +
|
| 101 | +$Settings = New-ScheduledTaskSettingsSet ` |
| 102 | + -ExecutionTimeLimit (New-TimeSpan -Days 3) ` |
| 103 | + -StartWhenAvailable:$true ` |
| 104 | + -MultipleInstances "IgnoreNew" ` |
| 105 | + -RunOnlyIfIdle:$false |
| 106 | +
|
| 107 | +$Principal = New-ScheduledTaskPrincipal ` |
| 108 | + -UserId $User ` |
| 109 | + -LogonType Password ` |
| 110 | + -RunLevel Highest |
| 111 | +
|
| 112 | +$Task = New-ScheduledTask ` |
| 113 | + -Action $Action ` |
| 114 | + -Trigger $Trigger ` |
| 115 | + -Settings $Settings ` |
| 116 | + -Principal $Principal |
| 117 | +
|
| 118 | +Register-ScheduledTask ` |
| 119 | + -TaskName "MSTeamsObservabilityAgent" ` |
| 120 | + -InputObject $Task ` |
| 121 | + -User $Credential.UserName ` |
| 122 | + -Password $PlainPassword ` |
| 123 | + -Force |
| 124 | +``` |
| 125 | + |
| 126 | +## Task Settings Summary |
| 127 | + |
| 128 | +| Setting | Value | Rationale | |
| 129 | +| --- | --- | --- | |
| 130 | +| **Trigger** | At startup | Starts collection as soon as the host boots | |
| 131 | +| **Multiple instances** | IgnoreNew | Prevents duplicate collector processes | |
| 132 | +| **Run level** | HighestAvailable | Ensures network and filesystem access | |
| 133 | +| **Execution time limit** | Unlimited (PT0S) / 3 days | Collector runs indefinitely; no hard timeout | |
| 134 | +| **Start when available** | true (PowerShell) | Retries if the task misses its scheduled start | |
| 135 | +| **Stop on batteries** | true | Preserves laptop battery when unplugged | |
| 136 | +| **Allow start on demand** | true | Lets you manually trigger a run from Task Scheduler | |
| 137 | + |
| 138 | +<Aside type="tip"> |
| 139 | +The collector logs to `stdout` and `stderr`. To capture logs, redirect output in the `<Arguments>`: |
| 140 | +`run --config "config.yaml" > "C:\Program Files\Phenisys\logs\agent.log" 2>&1` |
| 141 | +</Aside> |
| 142 | + |
| 143 | +## Verifying the Service |
| 144 | + |
| 145 | +1. Open **Task Scheduler** and locate `MSTeamsObservabilityAgent` |
| 146 | +2. Right-click → **Run** to test immediately |
| 147 | +3. Check **History** tab for execution results |
| 148 | +4. Verify data appears in your backend after one collection cycle |
| 149 | + |
| 150 | +## Stopping the Collector |
| 151 | + |
| 152 | +To stop the running collector: |
| 153 | + |
| 154 | +```powershell |
| 155 | +Stop-ScheduledTask -TaskName "MSTeamsObservabilityAgent" |
| 156 | +``` |
| 157 | + |
| 158 | +To permanently disable: |
| 159 | + |
| 160 | +```powershell |
| 161 | +Disable-ScheduledTask -TaskName "MSTeamsObservabilityAgent" |
| 162 | +``` |
| 163 | + |
| 164 | +To remove: |
| 165 | + |
| 166 | +```powershell |
| 167 | +Unregister-ScheduledTask -TaskName "MSTeamsObservabilityAgent" -Confirm:$false |
| 168 | +``` |
0 commit comments