Category filter
PowerShell scripts related to Diagnostic Data Viewer
Diagnostic data on Windows refers to the information collected and sent by the operating system to Microsoft to help identify and troubleshoot issues, improve system performance, and enhance user experiences. Using Diagnostic Data Viewer, users can view and analyze diagnostic data collected by the operating system.
With the provided PowerShell scripts, you can check the current status of Diagnostic Data Viewer, disable or enable diagnostic data viewing, and delete diagnostic data history when needed. Additionally, you can retrieve the diagnostic data store capacity and control how much diagnostic data history can be shown. Admins can deploy these scripts to multiple devices using Hexnode’s Execute Custom Script feature.
PowerShell script
Use the following script to install the Nuget and Microsoft.DiagnosticDataViewer module on the Windows device. These modules are required to execute the other scripts described in the document.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
try { if(Get-PackageProvider | Where-Object {$_.Name -eq "Nuget"}) { "Nuget Module already exists" } else { "Installing nuget module" Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force } Install-Module Microsoft.DiagnosticDataViewer -Force } catch { Write-Output $_.Exception.Message } |
Check diagnostic data status
The command fetches the current state of Diagnostic Data Viewer and checks whether it is enabled or disabled on the device.
1 |
Get-DiagnosticDataViewingSetting |
Disable and delete diagnostic data
Disable diagnostic data viewing and delete all diagnostic data history on the device using the following command.
1 |
Disable-DiagnosticDataViewing |
Enable diagnostic data
Enable diagnostic data viewing on the device using the following command. Once enabled, the device will log every diagnostic data event sent to Microsoft.
1 |
Enable-DiagnosticDataViewing |
Fetch the diagnostic store capacity
The command fetches the current diagnostic store capacity, showing the size in megabytes and time in days. The default capacity is 1024 MB and 30 days. When either limit is met (whichever happens first), the diagnostic data is removed in a first-in-first-out manner. For instance, if the size limit is 2GB and the time limit is 45 days, the oldest entry will be discarded once the storage reaches 2GB or the oldest event is 30 days old (whichever occurs first).
To obtain the configured store capacity (in megabytes) of the diagnostic store, execute the following command:
1 |
Get-DiagnosticStoreCapacity -Size |
To obtain the configured store capacity (in hours) of the diagnostic store, execute the following command:
1 |
Get-DiagnosticStoreCapacity -Time |
Set the diagnostic store capacity
This command allows you to configure the maximum amount of diagnostic data history that can be displayed. You can set the size cap in megabytes and the time cap in days. When either cap is reached, diagnostic data history is removed in a first-in-first-out order.
To set the size capacity of the diagnostic store to 512 (in megabytes), execute the following command:
1 |
Set-DiagnosticStoreCapacity -Size 512 |
To set the time capacity of the diagnostic store to 12 (in hours), execute the following command:
1 |
Set-DiagnosticStoreCapacity -Time 12 |
Fetch diagnostic data history
This command retrieves the historical Windows diagnostic data uploaded by this machine. The amount of available historical data is constrained by the configurations of the diagnostic data store. For modifications in the diagnostic store capacity, refer to Set the diagnostic store capacity.
The following command will retrieve all diagnostic events occurred within the time frame of 20 and 6 hours before the script execution time.
1 |
Get-DiagnosticData -StartTime (Get-Date).AddHours(-20) -EndTime (Get-Date).AddHours(-6) |
The following command will retrieve the first (oldest) diagnostic event since the previous ‘n’ days.
1 |
Get-DiagnosticData -StartTime (Get-Date).AddDays(-1) -RecordCount 1 |
The parameter -RecordCount specifies the maximum number of events to retrieve.