// src/generators/intune-detection.ts // Generates a PowerShell detection script for Microsoft Intune compliance checks. // // CRITICAL design constraints (from Microsoft Learn): // - Exit 0 + Write-Output → app detected (compliant) // - Any STDERR output → app NOT detected, even with exit 0 // - Therefore: NO $ErrorActionPreference = 'Stop' here — unhandled exceptions // write to STDERR, which Intune interprets as non-detection regardless of exit code // - NO Write-Error, NO Write-Host (Write-Host goes to the information stream in PS 5+, // which Intune may capture differently depending on host; Write-Output is safest) import type { WizardState } from '../store/types'; import { CONFIG_DIR } from './ps-helpers'; export function buildIntuneDetection(state: WizardState): string { const configDir = CONFIG_DIR[state.deployment.configPath]; return [ `$configDir = '${configDir}'`, `$rclonePath = "$configDir\\rclone.exe"`, `$configPath = "$configDir\\rclone.conf"`, ``, `if ((Test-Path $rclonePath) -and (Test-Path $configPath)) {`, ` Write-Output "rclone and config detected"`, ` exit 0`, `} else {`, ` exit 1`, `}`, ].join('\n') + '\n'; }