<# .SYNOPSIS Installs the MARS (Azure Backup agent) collector as a SYSTEM scheduled task. .DESCRIPTION - Copies Send-MarsBackupStatus.ps1 to Program Files (only admins can modify it, which matters because it runs as SYSTEM). - Writes the config to ProgramData\BackupDashboard and restricts that folder to SYSTEM and Administrators, since it contains the API key. - Registers a scheduled task that runs every IntervalMinutes under Windows PowerShell 5.1 (powershell.exe), which the agent's MSOnlineBackup module targets. Safe to re-run to change settings or update the script. Can sit alongside the Veeam collector. .EXAMPLE .\Install-MarsCollector.ps1 -ApiUrl https://backups.example.com -Tenant "Acme Corp" (prompts for the API key) #> #Requires -RunAsAdministrator [CmdletBinding()] param( [Parameter(Mandatory)][string]$ApiUrl, [Parameter(Mandatory)][string]$Tenant, # Name shown on the dashboard; defaults to " - Azure Backup" [string]$JobName, [string]$SourceSystem = 'Azure Backup (MARS)', [ValidateRange(5, 1440)][int]$IntervalMinutes = 60, [ValidateRange(1, 720)][int]$LookbackHours = 48, [string]$InstallDir = (Join-Path $env:ProgramFiles 'BackupDashboard') ) $ErrorActionPreference = 'Stop' $WindowsPowerShell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe' # Check the agent is here before changing anything $agentModule = Join-Path $env:ProgramFiles 'Microsoft Azure Recovery Services Agent\bin\Modules\MSOnlineBackup' if (-not (Get-Module -ListAvailable -Name MSOnlineBackup) -and -not (Test-Path $agentModule)) { throw 'The MARS agent (MSOnlineBackup PowerShell module) is not installed on this server.' } # Shared installer code: in the repo it's in ..\common, so copy the whole collectors folder $sharedModule = @( (Join-Path $PSScriptRoot 'BackupDashboard.Collector.psm1'), (Join-Path (Join-Path (Join-Path $PSScriptRoot '..') 'common') 'BackupDashboard.Collector.psm1') ) | Where-Object { Test-Path $_ } | Select-Object -First 1 if (-not $sharedModule) { throw "BackupDashboard.Collector.psm1 not found. Copy the whole collectors folder, including common." } Import-Module $sharedModule -Force $settings = [ordered]@{ Tenant = $Tenant; SourceSystem = $SourceSystem; LookbackHours = $LookbackHours } if ($JobName) { $settings.JobName = $JobName } Install-CollectorTask -Name 'mars' -ScriptPath (Join-Path $PSScriptRoot 'Send-MarsBackupStatus.ps1') ` -TaskName 'Backup Dashboard - MARS collector' ` -TaskDescription 'Sends Azure Backup (MARS) results to the Backup Dashboard' ` -Shell $WindowsPowerShell -ApiUrl $ApiUrl -IntervalMinutes $IntervalMinutes -InstallDir $InstallDir -Settings $settings