🟣 C# / .NET 6+

Backup Computer System Product Info to JSON (C#)

Snapshots Computer System Product Info (Win32_ComputerSystemProduct) to a timestamped JSON file via System.Management and System.Text.Json.

By WindowsScripting.com · 1.3 KB
BackupComputerSystemProductListToJson.cs
// BackupComputerSystemProductListToJson.cs
//
// Snapshots Computer System Product Info (Win32_ComputerSystemProduct) to a timestamped JSON file.
//
// Requires the System.Management package:
//   dotnet new console -o BackupComputerSystemProduct
//   dotnet add package System.Management
//   (replace the generated Program.cs with this file, then dotnet run)

using System;
using System.Collections.Generic;
using System.IO;
using System.Management;
using System.Text.Json;

var searcher = new ManagementObjectSearcher("SELECT Name, Vendor, Version, IdentifyingNumber FROM Win32_ComputerSystemProduct");
var results = new List<Dictionary<string, object?>>();

foreach (ManagementObject item in searcher.Get())
{
    var row = new Dictionary<string, object?>();
    row["Name"] = item["Name"];
        row["Vendor"] = item["Vendor"];
        row["Version"] = item["Version"];
        row["IdentifyingNumber"] = item["IdentifyingNumber"];
    results.Add(row);
}

string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
string outPath = $"computersystemproduct-snapshot_{timestamp}.json";
File.WriteAllText(outPath, JsonSerializer.Serialize(results, new JsonSerializerOptions { WriteIndented = true }));

Console.WriteLine($"Snapshot of Computer System Product Info ({results.Count} items) saved to {outPath}");