getDiskInfo
getDiskInfo
Info
getDiskInfo is a synchronous query function that returns physical disk drive information. It spawns the C# helper EXE which queries Win32_DiskDrive via WMI, returning an array of DiskInfo objects.
Signature
function getDiskInfo(): DiskInfo[];Return Value
| Type | Description |
|---|---|
DiskInfo[] | Array of physical disk information objects |
Warning
This returns physical disks, not logical volumes. A single disk with 3 partitions still appears as one entry.
Usage
Use this function to list installed storage devices, check disk models and sizes, or build a hardware inventory.
Note
This function returns disk hardware information (model, capacity, interface). It does not report partition layouts, file systems, or free space.
Tips
Use partitions to determine if a disk is in use. A disk with 0 partitions is likely unallocated or raw.
Example
import { getDiskInfo } from '@eisland/windows-hardware-info-helper';
const disks = getDiskInfo();
for (const disk of disks) {
const sizeGB = (disk.sizeBytes ?? 0) / 1073741824;
const sizeStr = sizeGB >= 1024 ? `${(sizeGB / 1024).toFixed(1)} TB` : `${sizeGB.toFixed(0)} GB`;
console.log(`${disk.model} — ${sizeStr}`);
console.log(` Interface: ${disk.interfaceType}, Partitions: ${disk.partitions}`);
}const { getDiskInfo } = require('@eisland/windows-hardware-info-helper');
const disks = getDiskInfo();
for (const disk of disks) {
const sizeGB = (disk.sizeBytes ?? 0) / 1073741824;
const sizeStr = sizeGB >= 1024 ? `${(sizeGB / 1024).toFixed(1)} TB` : `${sizeGB.toFixed(0)} GB`;
console.log(`${disk.model} — ${sizeStr}`);
console.log(` Interface: ${disk.interfaceType}, Partitions: ${disk.partitions}`);
}Notes
Note
NVMe drives report interfaceType as "SCSI" because Windows routes NVMe through the SCSI subsystem. This is expected behavior.
Tips
USB external drives are included if they report as physical disks. Filter by interfaceType if you need only internal drives.
Important
The serialNumber field may be null for some drives, especially USB-attached ones or older models that do not expose serial numbers via WMI.
Danger Avoidance
Caution
Do not use sizeBytes for precise byte-level calculations. WMI reports nominal capacity (e.g., 2TB = 2,000,000,000,000 bytes), which differs from the OS-reported usable capacity due to base-10 vs base-2 conversion.
Changelog
bb5b2-on

