🟣 C# / .NET 6+

Get Physical Disk Drives Report (C#)

Queries Win32_DiskDrive via WMI (System.Management) and prints Physical Disk Drives to the console.

By WindowsScripting.com · 1 KB
GetDiskDriveReport.cs
// GetDiskDriveReport.cs
//
// Reports Physical Disk Drives via WMI (Win32_DiskDrive).
//
// Requires the System.Management package:
//   dotnet new console -o DiskDriveReport
//   dotnet add package System.Management
//   (replace the generated Program.cs with this file, then dotnet run)
// On .NET Framework, System.Management is already available — just
// add a reference to it in your project.

using System;
using System.Management;

var searcher = new ManagementObjectSearcher("SELECT Model, Size, InterfaceType, Status FROM Win32_DiskDrive");
int count = 0;

foreach (ManagementObject item in searcher.Get())
{
    Console.WriteLine($"Model: {item["Model"]}");
    Console.WriteLine($"Size: {item["Size"]}");
    Console.WriteLine($"InterfaceType: {item["InterfaceType"]}");
    Console.WriteLine($"Status: {item["Status"]}");
    Console.WriteLine(new string('-', 40));
    count++;
}

if (count == 0)
{
    Console.WriteLine("No Physical Disk Drives found.");
}
else
{
    Console.WriteLine($"\n{count} Physical Disk Drives found.");
}