🟣 C# / .NET 6+
Backup Computer System Info to JSON (C#)
Snapshots Computer System Info (Win32_ComputerSystem) to a timestamped JSON file via System.Management and System.Text.Json.
BackupComputerSystemListToJson.cs
// BackupComputerSystemListToJson.cs
//
// Snapshots Computer System Info (Win32_ComputerSystem) to a timestamped JSON file.
//
// Requires the System.Management package:
// dotnet new console -o BackupComputerSystem
// 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, Manufacturer, Model, TotalPhysicalMemory, NumberOfProcessors FROM Win32_ComputerSystem");
var results = new List<Dictionary<string, object?>>();
foreach (ManagementObject item in searcher.Get())
{
var row = new Dictionary<string, object?>();
row["Name"] = item["Name"];
row["Manufacturer"] = item["Manufacturer"];
row["Model"] = item["Model"];
row["TotalPhysicalMemory"] = item["TotalPhysicalMemory"];
row["NumberOfProcessors"] = item["NumberOfProcessors"];
results.Add(row);
}
string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
string outPath = $"computersystem-snapshot_{timestamp}.json";
File.WriteAllText(outPath, JsonSerializer.Serialize(results, new JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine($"Snapshot of Computer System Info ({results.Count} items) saved to {outPath}");