Public/Get-MDMPolicyReport.ps1
<# .SYNOPSIS Script to create a html report about Intune policies applied to a system .DESCRIPTION #************************************************************************************************************ # Disclaimer # # This sample script is not supported under any Microsoft standard support program or service. This sample # script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties # including, without limitation, any implied warranties of merchantability or of fitness for a particular # purpose. The entire risk arising out of the use or performance of this sample script and documentation # remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, # production, or delivery of this script be liable for any damages whatsoever (including, without limitation, # damages for loss of business profits, business interruption, loss of business information, or other # pecuniary loss) arising out of the use of or inability to use this sample script or documentation, even # if Microsoft has been advised of the possibility of such damages. # #************************************************************************************************************ This script generates a HTML report of Intune policies from the MDM Diagnostics Report XML, HTML and AppWorkload.log files The script can be run locally on a device to generate a new report or it can be run with the MDMDiagReportPath parameter to use an existing MDM Diagnostics export folder. The report includes information about Intune script policies, LAPS settings, firewall settings, and more. .LINK https://aka.ms/IntuneDebug .PARAMETER MDMDiagReportPath Path to the MDM Diagnostics export folder. The folder should contain the MDMDiagReport.xml file, the MDMDiagReport.html file, and the IntuneManagementExtension AppWorkload.log files. If not provided, a new report of the system running the script on will be generated. .PARAMETER CleanUpDays Number of days to keep the MDM Diagnostics report folders. Default is 1 day. Folders older than this number of days will be removed from the MDM Diagnostics folder. This parameter only applies to the report data generated by this script. #> function Get-MDMPolicyReport { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [string]$MDMDiagReportPath, [Parameter(Mandatory = $false)] [int]$CleanUpDays = 1 ) $moduleVersion = '4.0.1' # Lets cleanup any previous Intune report data Invoke-IntuneReportDataCleanup -CleanUpDays $CleanUpDays # Making the MDMDiagReportPath a script variable to be used in other functions $script:MDMDiagReportPathVariable = $MDMDiagReportPath $MDMDiagReportXml = Get-IntunePolicyDataFromXML -MDMDiagReportPath $MDMDiagReportPath $MDMDiagReportHTMLPath = $MDMDiagReportXml.FileFullName -replace '.xml', '.html' if (-Not (Test-Path -Path $MDMDiagReportHTMLPath)) { Write-Error "The specified MDM Diagnostics HTML Report file does not exist: `"$MDMDiagReportHTMLPath`"" return } $script:MDMDiagHTMLReportPathVariable = $MDMDiagReportHTMLPath $script:enrollmentProviderIDs = Get-EnrollmentProviderIDs -MDMData $MDMDiagReportXml.XMlFileData # Initialize a list to hold all Intune policies $IntunePolicyList = [System.Collections.Generic.List[pscustomobject]]::new() Get-IntunePolicySystemInfo -HtmlReportPath $MDMDiagReportHTMLPath | ForEach-Object { $IntunePolicyList.Add($_) } Get-IntuneDeviceAndUserPolicies -MDMData $MDMDiagReportXml.XMlFileData | ForEach-Object { $IntunePolicyList.Add($_) } Get-IntuneMSIPolicies -MDMData $MDMDiagReportXml.XMlFileData | ForEach-Object { $IntunePolicyList.Add($_) } Get-IntuneResourcePolicies -MDMData $MDMDiagReportXml.XMlFileData | ForEach-Object { $IntunePolicyList.Add($_) } Get-IntunePoliyLAPSData -MDMData $MDMDiagReportXml.XMlFileData | ForEach-Object { $IntunePolicyList.Add($_) } # name of the file to save the HTML report $outFile = '{0}\IntunePolicyReport.html' -f (Split-Path -Path $MDMDiagReportHTMLPath -Parent) # Convert the policies to HTML and save to the specified output path Convert-IntunePoliciesToHtml -OutputPath $outFile -Policies $IntunePolicyList -Title "Intune Policy Report v$moduleVersion" # Open the generated HTML report in Microsoft Edge Start-Process "msedge.exe" -ArgumentList $outFile } |