PowerShellMicrosoft GraphPHP Intune

Intune Configuration Automation for MS-102 Preparation

Automation scripts for Intune configurations supporting exam preparation and enterprise requirements.

📖 Read Full Engineering Guide → 🐙 GitHub Repo
### FILE: index.php
<?php

// Ensure session includes the necessary Microsoft Graph access token.
if (!isset($_SESSION['ms_access_token'])) {
    die('Access token missing');
}

// Example of calling the Graph API and handling exceptions.
try {
    $deviceID = 'exampleDeviceID';
    $policyID = 'examplePolicyID';
    $response = $ms->graphCall('/deviceManagement/deviceCompliancePolicies', $_SESSION['ms_access_token'], 'POST', [
        'deviceId' => $deviceID,
        'policyId' => $policyID
    ]);

    render_premium_card(
        'Compliance Configuration',
        'Configuration applied successfully',
        null,
        'up',
        '📊',
        100
    );
} catch (Exception $e) {
    render_premium_card(
        'Compliance Configuration Error',
        'Error applying configuration: ' . $e->getMessage(),
        null,
        'down',
        '⚠️',
        0
    );
}

?>

### FILE: scripts/Automation.ps1
<#
.SYNOPSIS
Automates the Intune device compliance policy application.

.DESCRIPTION
This script connects to Microsoft Graph and applies a device compliance policy
to a specified device via Intune, providing feedback on success or failure.

.EXAMPLE
./Automation.ps1 -DeviceID "device-id" -PolicyID "policy-id"

.NOTES
    Author:      Souhaiel Morhag
    Company:     MSEndpoint.com
    Blog:        https://msendpoint.com
    Academy:     https://app.msendpoint.com/academy
    LinkedIn:    https://linkedin.com/in/souhaiel-morhag
    GitHub:      https://github.com/Msendpoint
    License:     MIT
#>

param (
    [string]$DeviceID,
    [string]$PolicyID
)

try {
    # Connect to Microsoft Graph
    Connect-MgGraph -Scopes "DeviceManagementConfiguration.ReadWrite.All"

    # Apply compliance policy
    Set-MgDeviceManagementDeviceCompliancePolicy -DeviceId $DeviceID -PolicyId $PolicyID

    # Output success message
    Write-Host "Configuration applied successfully." -ForegroundColor Green
} catch {
    # Handle errors
    Write-Host "Error applying configuration: $_" -ForegroundColor Red
}

⚠️ Always review and validate PowerShell scripts in a non-production pilot group before tenant-wide deployment.

🎓 Preparing for MD-102, SC-300, AZ-104 or AB-650?

Practice 1,060+ Microsoft Learn-verified exam questions in Pearson VUE simulator mode.

Free MD-102 Exam → vs MeasureUp