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.

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

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.

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.

Get the current status of diagnostic data viewing

Disable and delete diagnostic data

Disable diagnostic data viewing and delete all diagnostic data history on the device using the following command.

Disable diagnostic data viewing and delete all diagnostic data history

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.

Diagnostic data viewing is enabled on the device

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:

Get the diagnostic store size capacity

To obtain the configured store capacity (in hours) of the diagnostic store, execute the following command:

Get the diagnostic store time capacity

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:

Set a custom diagnostic size capacity

To set the time capacity of the diagnostic store to 12 (in hours), execute the following command:

Set a custom diagnostic time capacity

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.

Get all the diagnostic events occurred between a period of time

The following command will retrieve the first (oldest) diagnostic event since the previous ‘n’ days.

The parameter -RecordCount specifies the maximum number of events to retrieve.

Get the oldest diagnostic event since the previous ‘n’ days

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository