Scripts/Invoke-SMBeatCollector.ps1

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

$ErrorActionPreference = 'Stop'

Import-Module SMBeat -ErrorAction Stop

$root = Join-Path $env:ProgramData 'SMBeat'
$config = $null
$configPath = Join-Path $root 'config.json'
if (Test-Path -LiteralPath $configPath) {
    $config = Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json
}

$splat = @{
    ErrorAction = 'Stop'
}
if ($config) {
    if ($config.Path) { $splat['Path'] = [string]$config.Path }
    if ($config.IntervalSec) { $splat['IntervalSec'] = [int]$config.IntervalSec }
    if ($config.RetentionDays) { $splat['RetentionDays'] = [int]$config.RetentionDays }
    if ($null -ne $config.IncludeSessions) { $splat['IncludeSessions'] = [bool]$config.IncludeSessions }
    if ($null -ne $config.IncludeAdminShares) { $splat['IncludeAdminShares'] = [bool]$config.IncludeAdminShares }
    if ($null -ne $config.IncludeNics) { $splat['IncludeNics'] = [bool]$config.IncludeNics }
}

Invoke-SMBeatSample @splat