Public/Start-IntuneDiff.ps1

# Copyright (c) 2026 Sandy Zeng. All rights reserved.
# Source-available. All rights reserved. See LICENSE file.

<#
    Start-IntuneDiff.ps1 — Public entry point. Validates environment and launches the main WPF window.
 
    Author: Sandy Zeng
    Project: IntuneDiff
 
    Version History:
    1.0.0 Initial release.
#>


function Start-IntuneDiff {
    <#
    .SYNOPSIS
        Launches the IntuneDiff WPF GUI tool.
 
    .DESCRIPTION
        Opens a window where you can sign in to Microsoft Graph, compare Intune
        configuration policies, search a device's settings, and compare a device
        against selected policies.
 
        Requires Windows + PowerShell 7+ in STA mode.
 
    .EXAMPLE
        PS> Start-IntuneDiff
 
    .EXAMPLE
        PS> Start-IntuneDiff -ShowLog
        # Shows diagnostic logging in the console (auth, Graph calls, UI state)
    #>

    param(
        [switch]$ShowLog
    )

    # Enable module-wide verbose logging if -ShowLog was passed
    $script:VerboseMode = $ShowLog.IsPresent

    if (-not $IsWindows) {
        throw 'Start-IntuneDiff requires Windows (WPF is Windows-only).'
    }

    if ([System.Threading.Thread]::CurrentThread.GetApartmentState() -ne 'STA') {
        $msg = @(
            'PowerShell is running in MTA mode but WPF requires STA.',
            'Restart PowerShell with: pwsh -STA',
            'or run: Start-Process pwsh -ArgumentList ''-STA'',''-NoExit'',''-Command'',''Import-Module IntuneDiff; Start-IntuneDiff'''
        ) -join "`n"
        throw $msg
    }

    if (-not (Get-Module -ListAvailable -Name 'Microsoft.Graph.Authentication')) {
        throw 'The Microsoft.Graph.Authentication module is required. Install with: Install-Module Microsoft.Graph.Authentication -Scope CurrentUser'
    }

    Import-Module Microsoft.Graph.Authentication -ErrorAction Stop

    Show-MainWindow
}