By Jon Lynn – Sr. Service Engineer | Microsoft Endpoint Manager – Intune
Updated 7/29/21: We're excited to share that the Windows 10 Device diagnostics feature is now generally available! See our What’s New in Microsoft Endpoint Manager - 2107 (July) Edition post to learn more. You can also see it in action here.
In our 2102 (February) Microsoft Intune service release we are enabling a public preview of the Windows 10 Device diagnostics feature. We’ve listened to your feedback and understand that troubleshooting, especially with the emphasis on remote work, can be particularly challenging. This first release of device diagnostics utilizes the Windows DiagnosticLog CSP, allowing Intune to collect a set of files, registry, event viewers and commands to be gathered on a Windows 10 or a Microsoft HoloLens 2 device. The diagnostic process is quite easy, fast, and reliable, generally taking about 5 minutes from start to finish.
Let’s take a look at the requirements to use device diagnostics:
Client requirements
Intune requirements
Once the client and Intune requirements are met, simply navigate in the Microsoft Endpoint Manager admin center to the Devices > All Devices blade and search for the device you want to collect diagnostics on.
All devices blade in the MEM admin center
Double click on the device and choose the device action “Collect diagnostics”.
Single device view in the MEM admin center
The status and results of the Collect diagnostics task can be found under Device diagnostics (Preview). Once opened, the monitor displays who ran the Collect diagnostics task, status, when it was started, when diagnostics were uploaded, and a download button when complete (if successful).
There are three status messages for a diagnostic task, let us review each:
Here’s what a pending and completed diagnostic collection status looks like:
Device diagnostics (Preview) example
Device diagnostics (Preview) download example
Now that the diagnostic has completed, click download, save to your machine, and extract the zip file. You will know notice the zip file has many folders. This can be confusing and unfortunately, it’s not something we can change because that is how the DiagnosticLog CSP handles the files. However, we are working on an update to flatten the folders and simplify the process after diagnostics are gathered. To help simplify the diagnostics during the preview, please see the PowerShell script provided later in the blog.
Each file, command, registry, or event viewers is stored in an individual folder to be compressed into a zip file, see the image below for a sample of the zip and contents.
Fig 1. Example of the samples of the zip and contents
Fig 2. Example of the samples of the zip and contents
Fig 3. Example of the samples of the zip and contents
Now that we have reviewed how to collect diagnostics, let’s review what we are collecting from machines. Currently we collect useful registry keys, command outputs, MDM diagnostic logs and other critical Microsoft data like Microsoft Defender ATP logs.
Also, it is important to note, there are restrictions on what and where we can gather data using the DiagnosticLog CSP. We cannot collect information from user data folders, nor non-diagnostic file types, like photo or document file types. I highly encourage you to review the DiagnosticLog CSP documentation here for all the details. Microsoft personnel may access device diagnostics to assist in troubleshooting and resolving incidents. The logs are encrypted at rest after uploading them.
Here is the standard diagnostics template Intune is collecting and what it’s useful for:
Windows 10 Desktop OS:
Commands:
Event Viewers: We are capturing the common event viewers for troubleshooting issues, including Application, System and Setup. In addition, we are capturing the AppLocker event viewers to assist in debugging AppLocker issues and the SENSE event viewers to help debugging issues with anti-virus/malware.
Files: These commands collect the files generated during the log collection and files on the machine used for debugging issues. We are capturing all the data mentioned earlier along with Configuration Manager setup and client logs, CBS logs for issues and measured boot ETL’s to assist in machine security issues.
HoloLens 2:
Commands:
Folders/Files:
%programdata%\MDMDiagnostics\mdmlogs-<Date/Time>.zip
%ProgramData%\Microsoft\DiagnosticLogCSP\Collectors\*.etl
%windir%\logs\measuredboot\*.*
For the public preview we have created a PowerShell script that will take the downloaded zip file and convert it into a simplified folder file with updated file names to describe each one and removing all the folders.
To use the PowerShell script, simply open a PowerShell prompt, and use the name of the download file as the input for the script.
Example: Devicediagnostics.ps1 Download.zip
Device diagnostics PowerShell Script:
param($DiagnosticArchiveZipPath)
#region Formatting Choices
$flatFileNameTemplate = '({0:D2}) {1} {2}'
$maxLengthForInputTextPassedToOutput = 80
#endregion
#region Create Output Folders and Expand Zip
$diagnosticArchiveTempUnzippedPath = $DiagnosticArchiveZipPath + "_expanded"
if(-not (Test-Path $diagnosticArchiveTempUnzippedPath)){mkdir $diagnosticArchiveTempUnzippedPath}
$reformattedArchivePath = $DiagnosticArchiveZipPath + "_formatted"
if(-not (Test-Path $reformattedArchivePath)){mkdir $reformattedArchivePath}
Expand-Archive -Path $DiagnosticArchiveZipPath -DestinationPath $diagnosticArchiveTempUnzippedPath
#endregion
#region Discover and Move/rename Files
$resultElements = ([xml](Get-Content -Path (Join-Path -Path $diagnosticArchiveTempUnzippedPath -ChildPath "results.xml"))).Collection.ChildNodes | Foreach-Object{ $_ }
$n = 1
# only process supported directives
$supportedDirectives = @('Command', 'Events', 'FoldersFiles', 'RegistryKey')
foreach( $element in $resultElements) {
# only process supported directives, skip unsupported ones
if(!$supportedDirectives.Contains($element.Name)) { continue }
$directiveNumber = $n
$n++
$directiveType = $element.Name
$directiveStatus = [int]$element.Attributes.ItemOf('HRESULT').psbase.Value
$directiveUserInputRaw = $element.InnerText
# trim the path to only include the actual command - not the full path
if ($element.Name -eq 'Command') {
$lastIndexOfSlash = $directiveUserInputRaw.LastIndexOf('\');
$directiveUserInputRaw = $directiveUserInputRaw.substring($lastIndexOfSlash+1);
}
$directiveUserInputFileNameCompatible = $directiveUserInputRaw -replace '[\\|/\[\]<>\:"\?\*%\.\s]','_'
$directiveUserInputTrimmed = $directiveUserInputFileNameCompatible.substring(0, [System.Math]::Min($maxLengthForInputTextPassedToOutput, $directiveUserInputFileNameCompatible.Length))
$directiveSummaryString = $flatFileNameTemplate -f $directiveNumber,$directiveType,$directiveUserInputTrimmed
$directiveOutputFolder = Join-Path -Path $diagnosticArchiveTempUnzippedPath -ChildPath $directiveNumber
$directiveOutputFiles = Get-ChildItem -Path $directiveOutputFolder -File
foreach( $file in $directiveOutputFiles) {
$leafSummaryString = $directiveSummaryString,$file.Name -join ' '
Copy-Item $file.FullName -Destination (Join-Path -Path $reformattedArchivePath -ChildPath $leafSummaryString)
}
}
#endregion
Remove-Item -Path $diagnosticArchiveTempUnzippedPath -Force -Recurse
Standard Zip versus PowerShell converted folder:
Comparison of Standard Zip vs. PowerShell converted folder
Lastly, if your organization does not want to utilize device diagnostics and wants to prevent IT admins from collecting diagnostics, the feature can be completely disabled in the Tenant Administration workload in the Microsoft Endpoint Manager admin center. Navigate to Tenant Admin > Device diagnostics (Preview) and disable the feature. Only a global administrator or Intune administrator can make this change.
Screenshot of the Device diagnostics (Preview) feature in the MEM admin center
Frequently asked questions and known issues (FAQ):
We are excited to ship this feature and look forward to your feedback and comments. Let us know if you have any additional questions by replying to this post or reaching out to @IntuneSuppTeam on Twitter.
Post updates:
07/29/21: Windows 10 device diagnostics is now generally available!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.