Scripts/Invoke-SMBeatCollector.ps1

#Requires -Version 5.1
# Resident scheduled-task host. Runs locally on the file server as SYSTEM.

$ErrorActionPreference = 'Stop'

try {
    Import-Module SMBeat -ErrorAction Stop
    Watch-SMBeatCollector
}
catch {
    $root = Join-Path $env:ProgramData 'SMBeat'
    $line = '{0} {1}{2}' -f ([datetime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ssZ')), $_.Exception.Message, [Environment]::NewLine
    try {
        if (-not (Test-Path -LiteralPath $root)) {
            New-Item -ItemType Directory -Path $root -Force | Out-Null
        }
        $log = Join-Path $root 'collector.log'
        [System.IO.File]::AppendAllText($log, $line)
    }
    catch {
    }
    throw
}