用于识别驱动器是否为 NVMe 的 Windows API

问题描述 投票:0回答:1

如果驱动器是 NVMe 类型,是否有任何 Windows API 会返回?在 PowerShell 中,当我这样做时

Get-PhysicalDisk | select Friendlyname, BusType, MediaType 

它将 MediaType 指定为

SSD
,将 BusType 指定为
RAID
。早些时候,我使用
STORAGE_BUS_TYPE
win32 通过 BusType 检查 NVMe,但我有一个 SSD NVMe 设备,其 BusType 为 RAID。

powershell winapi nvme
1个回答
1
投票

我知道我有点晚了,但最近一直在做一个项目,并想出了这个可能有帮助的:

$bustype_table = @{ #bus type table taken from Microsofts webiste
    '0' = 'The bus type is unknown.'
    '1' = 'SCSI'
    '2' = 'ATAPI'
    '3' = 'ATA'
    '4' = 'IEEE 1394'
    '5' = 'SSA'
    '6' = 'Fibre Channel'
    '7' = 'USB'
    '8' = 'RAID'
    '9' = 'iSCSI'
    '10' = 'Serial Attached SCSI (SAS)'
    '11' = 'Serial ATA (SATA)'
    '12' = 'Secure Digital (SD)'
    '13' = 'Multimedia Card (MMC)'
    '14' = 'This value is reserved for system use (Virtual)'
    '15' = 'File-Backed Virtual'
    '16' = 'Storage spaces'
    '17' = 'NVMe'
}


try
{
    $windows_version = (Get-WmiObject Win32_OperatingSystem).Version #Gets windows version.
    if($windows_version -gt 10.0.00000) #has to be windows 10.0 or higher. wont work on 7 or 8.
   {
        $bustype = wmic /namespace:\\root\microsoft\windows\storage path msft_disk get BusType #,Model
        $bustype_value = $bustype[2].Trim() #trims whitespace from the bustype value.
        $drive_connection = $bustype_table[$bustype_value] #calls the table.
     Write-Host "The C drive is connected via: $drive_connection `r`n"
    }
}
catch
{
    $_.Exception.Message #windows version is pre windows 10. Script wont work.
}

具体来说,我认为这就是您想要的:

wmic /namespace:\\root\microsoft\windows\storage path msft_disk get Model,BusType

尽管如此,这可能不起作用,因为您已经声明您的 NVMe 驱动器处于 raid 中,因此它可能会将其拾取为“8”(RAID)。

让我知道进展如何。

© www.soinside.com 2019 - 2024. All rights reserved.