PowerShellMicrosoft GraphPHP Teams

Teams and Entra Conditional Access Automation

Scripts automate the deployment of Teams scam detection and Entra Conditional Access.

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

session_start();
$accessToken = $_SESSION['ms_access_token'];

try {
    // Call to fetch current Conditional Access Policies
    $endpoint = '/identity/conditionalAccess/policies';
    $policies = $ms->graphCall($endpoint, $accessToken);
    
    foreach ($policies as $policy) {
        render_premium_card(
            $policy['displayName'],
            'Enabled: ' . ($policy['state'] == 'enabled' ? 'Yes' : 'No'),
            null, 'up', '🔐'
        );
    }
    
} catch (Exception $e) {
    echo 'Error fetching policies: ' . $e->getMessage();
}

?>

### FILE: scripts/EntraConditionalAccess.ps1
<#
.SYNOPSIS
   Configures a Conditional Access policy for enhanced security in Entra ID.
.DESCRIPTION
   This script connects to Microsoft Graph and creates a Conditional Access Policy for token protection.
.EXAMPLE
   .\EntraConditionalAccess.ps1
.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
#>

try {
    Connect-MgGraph -Scopes "Policy.ReadWrite.ConditionalAccess"
    
    $policy = @{
        displayName = "Entra Token Protection Policy"
        conditions   = @{
            users     = @{
                includeUsers = @( 'All' )
            }
        }
        grantControls = @{
            builtIns = @( 'bi_tokenProtection' )
        }
        state         = 'enabled'
    }
    
    New-MgConditionalAccessPolicy -BodyParameter $policy
    Write-Host "Conditional Access policy created successfully."
} catch {
    Write-Error "Failed to create policy: $_"
}

⚠️ 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