Monday, 29 September 2025

Microsoft Intune Policy Configuration Templates-MS graph

 

<#

.SYNOPSIS

    Export Microsoft-provided Intune Compliance Policy Templates to HTML Dashboard

.NOTES

    Author: CloudTech797 Lab

    Date  : 2025-09-26

#>


# -------------------------------

# Step 0: Import required module

# -------------------------------

if (-not (Get-Module -ListAvailable -Name Microsoft.Graph.DeviceManagement)) {

    Install-Module Microsoft.Graph.DeviceManagement -Scope CurrentUser -Force

}

Import-Module Microsoft.Graph.DeviceManagement


# -------------------------------

# Step 1: Connect to Microsoft Graph Beta

# -------------------------------

$Scopes = @(

    "DeviceManagementConfiguration.Read.All"

)


# Disconnect any previous session

Try { Disconnect-MgGraph -Confirm:$false } Catch {}


Write-Host "Connecting to Microsoft Graph Beta..." -ForegroundColor Yellow

Connect-MgGraph -Scopes $Scopes -UseBeta -TenantId "cloudtech797.onmicrosoft.com"


Write-Host "Connected as: $((Get-MgContext).Account)" -ForegroundColor Green


# -------------------------------

# Step 2: Create report folder

# -------------------------------

$ReportFolder = "C:\Reports"

if (-not (Test-Path $ReportFolder)) { New-Item -ItemType Directory -Path $ReportFolder | Out-Null }

$ReportFile = "$ReportFolder\Intune_BuiltInCompliancePolicyTemplates_$(Get-Date -Format 'yyyyMMdd_HHmmss').html"


# -------------------------------

# Step 3: Fetch Microsoft-provided Compliance Policy Templates

# -------------------------------

Write-Host "Fetching built-in Compliance Policy Templates..." -ForegroundColor Yellow

$templates = Get-MgBetaDeviceManagementConfigurationPolicyTemplate | Where-Object { $_.TemplateType -eq "compliance" }


if ($templates.Count -eq 0) {

    Write-Warning "No compliance policy templates found."

    exit

}


# -------------------------------

# Step 4: Build HTML Dashboard

# -------------------------------

$style = @"

<style>

body { font-family: Arial; margin:20px; background:#f5f5f5; }

h1 { color:#0078D4; }

h2 { background:#0078D4; color:white; padding:10px; border-radius:5px; }

table { border-collapse: collapse; width: 100%; margin-bottom:20px; }

th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }

th { background:#e6e6e6; }

tr:nth-child(even) { background:#fafafa; }

</style>

"@


$html = "<html><head><title>Intune Built-in Compliance Policy Templates</title>$style</head><body>"

$html += "<h1>Microsoft-provided Intune Compliance Policy Templates</h1>"

$html += "<p>Generated on $(Get-Date)</p>"


# Group by platform

$platforms = $templates.Platforms | Select-Object -Unique

foreach ($platform in $platforms) {

    $platformTemplates = $templates | Where-Object { $_.Platforms -contains $platform }

    $html += "<h2>Platform: $platform</h2>"

    $html += ($platformTemplates | Select-Object DisplayName, Description, TemplateId | ConvertTo-Html -Fragment)

}


$html += "</body></html>"


# -------------------------------

# Step 5: Save & Open Report

# -------------------------------

$html | Out-File -FilePath $ReportFile -Encoding UTF8

Write-Host "HTML Dashboard generated: $ReportFile" -ForegroundColor Green


# Auto-open HTML

Start-Process $ReportFile