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


Tuesday, 23 September 2025

Automating Intune & Microsoft 365 Monitoring


Automating Intune & Microsoft 365 Monitoring

Introduction

Managing Intune and Microsoft 365 environments at scale requires automation to ensure proactive monitoring and faster remediation. Microsoft Graph API and PowerShell provide powerful ways to automate daily checks, consolidate reports, and reduce manual effort. This document outlines key areas where automation can be applied, with explanations of what can be monitored and how.

1. Service Health Check

·         Monitor Intune-related issues or advisories to detect outages or degradation.

·         Automation: Use Microsoft Graph Service Communications API to pull current advisories/incidents and schedule reports.

2. Device Compliance & Health

·         Non-Compliant Devices: Identify non-compliant devices and reasons.

·         Device Check-ins: Detect devices not checked in recently (e.g., 7 days).

·         Autopilot Deployment Status: Track deployment profiles and enrollment progress.

3. App Monitoring

·         App Deployment Failures: Identify failed/pending installations.

·         Pending App Approvals: Review user requests awaiting approval.

4. Configuration Profiles

·         Profile Deployment Status: Monitor failed/pending deployments.

·         Script Execution Failures: Detect failed Intune PowerShell scripts.

5. Endpoint Security

·         Policy Status: Monitor antivirus, firewall, encryption policies.

·         Threat Detection: Use Defender ATP/Graph Security API for incidents.

6. User Issues & Support

·         Helpdesk Tickets: Cross-reference device/app issues with compliance data.

·         Device Enrollment Failures: Track enrollment failures and causes.

7. Audit & Alerts

·         Audit Logs: Retrieve admin actions for compliance/governance.

·         Alerts & Notifications: Consolidate alerts from Intune, Azure AD, and Defender.

8. Licensing & Users

·         License Availability: Ensure sufficient license pool for Intune/EMS/M365.

·         User Assignment Issues: Detect unlicensed users and generate reports.

Conclusion

By leveraging Microsoft Graph API and PowerShell automation, administrators can reduce manual monitoring tasks across Intune and Microsoft 365. Automated jobs provide real-time insights, proactive alerts, and consolidated reporting, ensuring better visibility, faster response, and improved device/user experience.

 


HTML view:  




SCRIPT: Copy to notepad and Save as .ps1 file 

 <#

.SYNOPSIS

    Modular M365 / Intune Health Monitoring Report


.DESCRIPTION

    Connects to Microsoft Graph and collects:

    - Service Health

    - Device Compliance

    - Autopilot Devices

    - Defender Alerts

    - Licensing

    Outputs:

    - CSV exports

    - HTML summary report


.NOTES

    Author: Prasad Chenikala

#>


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

# 0. Graph SDK Environment Validator

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

function Validate-GraphEnvironment {

    Write-Host "`nChecking Microsoft Graph SDK installation..." -ForegroundColor Cyan

    $module = Get-InstalledModule Microsoft.Graph -ErrorAction SilentlyContinue | Sort-Object Version -Descending | Select-Object -First 1


    if ($null -eq $module) {

        Write-Host "Microsoft.Graph module not found. Please install it:" -ForegroundColor Red

        Write-Host "Install-Module Microsoft.Graph -Scope CurrentUser -Force"

        exit

    }


    Write-Host "Microsoft.Graph module version: $($module.Version)" -ForegroundColor Green

    Write-Host "Microsoft Graph SDK v2 detected and ready." -ForegroundColor Green

}


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

# 1. Initialization

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

function Initialize-Environment {

    $Global:Today = Get-Date -Format "yyyyMMdd"

    $Global:ReportPath = "$env:USERPROFILE\Documents\Reports\M365_Intune_Report_$Today"

    New-Item -ItemType Directory -Force -Path $ReportPath | Out-Null


    $Scopes = @(

        "DeviceManagementManagedDevices.Read.All",

        "DeviceManagementConfiguration.Read.All",

        "DeviceManagementApps.Read.All",

        "DeviceManagementServiceConfig.Read.All",

        "Directory.Read.All",

        "Reports.Read.All",

        "SecurityEvents.Read.All",

        "AuditLog.Read.All",

        "ServiceHealth.Read.All"

    )


    Connect-MgGraph -Scopes $Scopes -NoWelcome

}


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

# 2. Service Health

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

function Get-ServiceHealth {

    $data = Get-MgServiceAnnouncementHealthOverview

    $data | Export-Csv "$ReportPath\ServiceHealth.csv" -NoTypeInformation

    return $data

}


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

# 3. Device Compliance

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

function Get-DeviceCompliance {

    $nonCompliant = Get-MgDeviceManagementManagedDevice -Filter "complianceState ne 'compliant'"

    $nonCompliant | Export-Csv "$ReportPath\NonCompliantDevices.csv" -NoTypeInformation


    $stale = Get-MgDeviceManagementManagedDevice | Where-Object {

        $_.lastSyncDateTime -lt (Get-Date).AddDays(-7)

    }

    $stale | Export-Csv "$ReportPath\StaleDevices.csv" -NoTypeInformation


    return @{

        NonCompliant = $nonCompliant

        Stale = $stale

    }

}


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

# 4. Autopilot Devices

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

function Get-AutopilotDevices {

    $data = Get-MgDeviceManagementWindowsAutopilotDeviceIdentity

    $data | Export-Csv "$ReportPath\AutopilotDevices.csv" -NoTypeInformation

    return $data

}


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

# 5. Defender Alerts

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

function Get-DefenderAlerts {

    $data = Get-MgSecurityAlert -All

    $data | Export-Csv "$ReportPath\DefenderAlerts.csv" -NoTypeInformation

    return $data

}


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

# 6. Licensing

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

function Get-Licensing {

    $licenses = Get-MgSubscribedSku

    $licenses | Export-Csv "$ReportPath\Licenses.csv" -NoTypeInformation


    $users = Get-MgUser -All

    $userLicenses = @()

    foreach ($u in $users) {

        $userLicenses += Get-MgUserLicenseDetail -UserId $u.Id

    }

    $userLicenses | Export-Csv "$ReportPath\UserLicenses.csv" -NoTypeInformation


    return @{

        Licenses = $licenses

        Users = $userLicenses

    }

}


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

# 7. Build HTML Report

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

function Build-HtmlReport {

    param (

        $ServiceHealth,

        $DeviceCompliance,

        $Autopilot,

        $DefenderAlerts,

        $Licensing

    )


    $html = @'

<html>

<head>

<title>M365 and Intune Daily Report</title>

<style>

body { font-family: Arial; }

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

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

th, td { border: 1px solid #ddd; padding: 8px; }

th { background-color: #f2f2f2; }

</style>

</head>

<body>

<h1>M365 and Intune Daily Health Report - REPLACEME</h1>

'@


    $html = $html -replace 'REPLACEME', $Global:Today


    $html += '<h2>Service Health</h2>'

    $html += ($ServiceHealth | Select-Object workload, status | ConvertTo-Html -Fragment)


    $html += '<h2>Non-Compliant Devices</h2>'

    $html += ($DeviceCompliance.NonCompliant | Select-Object deviceName, userPrincipalName, complianceState, lastSyncDateTime | ConvertTo-Html -Fragment)


    $html += '<h2>Stale Devices (greater than 7 days no check-in)</h2>'

    $html += ($DeviceCompliance.Stale | Select-Object deviceName, userPrincipalName, lastSyncDateTime | ConvertTo-Html -Fragment)


    $html += '<h2>Autopilot Devices</h2>'

    $html += ($Autopilot | Select-Object serialNumber, deploymentProfileAssignmentStatus | ConvertTo-Html -Fragment)


    $html += '<h2>Defender Alerts</h2>'

    $html += ($DefenderAlerts | Select-Object title, severity, status, createdDateTime | ConvertTo-Html -Fragment)


    $html += '<h2>Licenses</h2>'

    $html += ($Licensing.Licenses | Select-Object skuPartNumber, consumedUnits, prepaidUnits | ConvertTo-Html -Fragment)


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


    $html | Out-File "$ReportPath\M365_Intune_Report.html" -Encoding utf8

}


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

# Main Execution

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

Validate-GraphEnvironment

Initialize-Environment


$ServiceHealth     = Get-ServiceHealth

$DeviceCompliance  = Get-DeviceCompliance

$Autopilot         = Get-AutopilotDevices

$DefenderAlerts    = Get-DefenderAlerts

$Licensing         = Get-Licensing


Build-HtmlReport -ServiceHealth $ServiceHealth `

                 -DeviceCompliance $DeviceCompliance `

                 -Autopilot $Autopilot `

                 -DefenderAlerts $DefenderAlerts `

                 -Licensing $Licensing


Write-Host "`nReport generated at $ReportPath" -ForegroundColor Green


Friday, 15 August 2025

Set up Intune to deploy and manage apps for Android

 

Set up Intune to deploy and manage apps for Android

Microsoft Intune is a cloud-based service that enhances data protection by managing devices and apps through mobile device management and mobile application management. It secures both organization and personal devices at the app level, protecting data even on non-enrolled devices.

How to manage and secure managed and unmanaged devices:

  • Google Play app configuration.
  • App protection policy creation and management.
  • Validate and manage data.
  • Monitor apps.

 

There are two types of devices to setup:

·         Managed Devices

·         Unmanaged Devices

How to Deploy applications and push configurations to the device

Device prerequisites:

Review managed Google Play connection

Required

Review Android OS requirements

Required

Meet Intune Network requirements

Required

Ship Android OS with Google Mobile Services (GMS) package

Required

Ensure Android Enterprise Service availability

Required

Set your tenant's mobile device management authority to Intune

Required

Assign Intune licenses to users

Required

Have users install the Company Portal App (no sign-in required)

Required

Set Google Zero Touch enrollment

Optional

Set Samsung Knox Zero Touch enrollment

Optional

 

Review managed Google Play connection:

Due to interaction between Google and Microsoft domains, you might need to adjust your browser settings to complete this process. Make sure that portal.azure.com, play.google.com, and enterprise.google.com are in the same security zone in your browser.

 

Review Android OS requirements:

Use user-less management methods on Android 8.0 and later devices. These methods are:

  • Android Enterprise dedicated
  • AOSP user-less

Set your tenant's mobile device management authority to Intune:

The mobile device management (MDM) authority setting is crucial for managing devices. As an IT admin, you need to set up an MDM authority before users can enroll devices for management. You must have an Intune license to set the MDM authority.

To set MDM authority

  1. Sign in to the Microsoft Intune admin center.
  2. If you haven't set the MDM authority yet, an orange banner will appear. Select it to open the Mobile Device Management Authority setting.
  3. Under Mobile Device Management Authority, choose Intune MDM Authority and confirm your selection.

https://intune.microsoft.com/#view/Microsoft_Intune_Enrollment/ChooseMDMAuthorityBlade

 

Assign Intune licenses to users:

To assign user and group licenses, follow these steps:

  1. Sign in to the Microsoft 365 admin center.
  2. Go to Billing and Licenses tab, and assign Intune licenses to the required users or groups

 

Configure managed devices:

Complete these tasks to enable Android Enterprise management options in the Intune portal:

·         Connect Intune to Managed Google Play

·         Manage Google Play apps

·         Assign apps to groups in Intune

·         Assign a Managed Google Play app

·         Update a Managed Google Play app

 

 

Connect Intune to Managed Google Play:

 

To manage devices enrolled in Intune with any of the supported Android Enterprise management options, you must connect your Intune tenant to your Managed Google Play account.

Get started

  1. Sign in to the Intune admin center.
  2. Go to the Devices tab, and under Device onboarding, select Enrollment.
  3. Select the Android tab.

  1. Under Android Enterprise >Prerequisites, select Managed Google Play.
  2. Under I grant Microsoft permission to send both user and device information to Google, select I agree.
  3. Select Launch Google to connect now to open the Managed Google Play website. The website opens on a new tab in your browser.
  4. On the Google sign-in page, confirm that the prefilled Microsoft Entra account is the account you want to associate with all Android Enterprise management tasks for this tenant.
    1. Add account. You can add an account with the proper license to perform the sync.
    2. Email confirmation. To perform the connection, the account must have a valid email account.
  5. Follow the onscreen prompts to finish creating a Google admin account.
  6. When prompted, select Allow and create account to allow Intune to manage your Android Enterprise devices.

 

 

Manage Google Play apps:

You can link your accounts in the Intune admin center after you connect to Google Play.

 

Get started

Complete these steps to add a Managed Google Play app directly in the Intune admin center.

  1. Sign in to the Intune admin center.
  2. Select Apps > All apps, and then select Add.
  3. In the Select app type pane, under the available Store app types, select Managed Google Play app.
  4. Select the Select button. The Managed Google Play app store is displayed.
  5. Select an app to view the app details.
  6. Choose Select to select the app.
  7. Select Sync at the top of the blade to sync the app with the Managed Google Play service.
  8. Refresh to update the app list and display the newly added app.

 

 

 

Assign apps to groups in Intune:

 

After you've added an app to Intune, you can assign the app to users and devices. You can deploy an app to a device whether or not the device is managed by Intune.

Get started

Follow these steps to assign apps to groups:

  1. Sign in to the Intune admin center.
  2. Select Apps, then select All apps.
  3. In the Apps pane, select the app you want to assign.
  4. In the Manage section of the menu, select Properties.
  5. Scroll down to Properties and select Assignments.
  6. Select Add Group to open the Add group pane that is related to the app.
  7. For the specific app, select an Assignment type:
    1. Available for enrolled devices. Assign the app to groups of users who can install the app from the Company Portal app or website.
    2. Available with or without enrollment. Assign this app to groups of users whose devices aren't enrolled with Intune. Users must be assigned an Intune license. For more information, see Microsoft Intune licensing.

If you deploy an Android app as "Available for enrolled devices," reporting status will be available only on enrolled devices.

    1. Required. The app is installed on devices in the selected groups. Some platforms may have additional prompts for the user to acknowledge before app installation begins.
    2. Uninstall. The app is uninstalled from devices in the selected groups if Intune has previously installed the application onto the device via an "Available for enrolled devices" or "Required assignment" using the same deployment.
  1. To select the groups of users that are affected by this app assignment, select Included Groups.
  2. After you have selected one or more groups to include, select Select.
  3. In the Assign pane, select OK to complete the included groups selection.
  4. If you want to exclude any groups of users from being affected by this app assignment, select Exclude Groups.
  5. If you have chosen to exclude any groups, in Select groups, select Select.
  6. In the Add group pane, select OK.
  7. In the app Assignments pane, select Save.