Public/Import-WingetAutoUpdateToIntune.ps1

<#
.SYNOPSIS
    Imports Winget AutoUpdate ADMX policies to Intune.
.DESCRIPTION
    Uploads ADMX template and creates ADMX-backed configuration policy for Winget AutoUpdate.
.EXAMPLE
    Import-WingetAutoUpdateToIntune
#>

function Import-WingetAutoUpdateToIntune {
    [CmdletBinding()]
    param(
        [switch]$DryRun
    )

    $ErrorActionPreference = "Stop"
    $workspacePath = Get-WorkspacePath
    if (-not $workspacePath) {
        Write-Error "Workspace not configured. Run Initialize-NLBaseline first."
        return
    }

    $config = Get-Config -WorkspacePath $workspacePath
    if (-not $config -or [string]::IsNullOrEmpty($config.AppRegistration.ClientId) -or [string]::IsNullOrEmpty($config.AppRegistration.ClientSecret) -or [string]::IsNullOrEmpty($config.AppRegistration.TenantId)) {
        Write-Error "App Registration not configured in config.json."
        return
    }

    Write-Host "`nImporting Winget AutoUpdate to Intune`n" -ForegroundColor Cyan

    if (-not $DryRun) {
        $connected = Connect-Intune -Config $config
        if (-not $connected) {
            Write-Error "Failed to connect to Microsoft Graph."
            return
        }
    }

    $admxPath = Join-Path -Path $PSScriptRoot -ChildPath "..\Resources\WingetAutoUpdate\WinGet-AutoUpdate-Configurator.admx"
    $admlPath = Join-Path -Path $PSScriptRoot -ChildPath "..\Resources\WingetAutoUpdate\WinGet-AutoUpdate-Configurator.adml"

    if (-not (Test-Path $admxPath)) {
        Write-Error "ADMX file not found: $admxPath"
        return
    }

    if ($DryRun) {
        Write-Host "[DryRun] Would upload ADMX template and create Winget AutoUpdate policy" -ForegroundColor Cyan
        return
    }

    try {
        Write-Host "Note: ADMX upload requires manual steps in Intune portal:" -ForegroundColor Yellow
        Write-Host "1. Go to: Devices > Configuration > Administrative Templates" -ForegroundColor White
        Write-Host "2. Click 'Create' > 'Import ADMX'" -ForegroundColor White
        Write-Host "3. Upload: $admxPath" -ForegroundColor White
        if (Test-Path $admlPath) {
            Write-Host "4. Upload ADML: $admlPath" -ForegroundColor White
        }
        Write-Host "5. Create policy using the imported template" -ForegroundColor White
        Write-Host "`nADMX files location: $admxPath" -ForegroundColor Cyan
        Write-Host "`nAlternatively, use Settings Catalog with custom OMA-URI for registry policies." -ForegroundColor Gray
    }
    catch {
        Write-Error "Failed to import Winget AutoUpdate: $_"
    }
}