将物理设备ID与卷设备ID相关联 [英] Correlate Physical Device ID to Volume Device ID

查看:117
本文介绍了将物理设备ID与卷设备ID相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过PowerShell利用WMI在远程服务器上的SAN存储中运行,以获取Windows磁盘管理卷标。

I'm trying to utilize WMI via PowerShell to run through SAN storage on remote servers to grab the Windows disk management volume label.

我发现这样做的唯一方法是关联卷设备ID( c?\\Volume {34243。 ..} 和物理磁盘设备ID( \\.\PHYSICALDRIVE01 )。

The only way I've found to do this is to correlate the volume device id (\\?\Volume{34243...} with the physical disk device ID (\\.\PHYSICALDRIVE01).

但是,我还无法找出如何将这两个字段链接在一起。使用WMI可以实现吗?

However, I haven't been able to find out how to link those two fields together. Is this possible with WMI?

推荐答案

对于分配了驱动器号的卷,您可以将磁盘和卷关联如下:

For volumes that were assigned a drive letter you can correlate disks and volumes like this:

Get-WmiObject Win32_DiskDrive | ForEach-Object {
  $disk = $_
  $partitions = "ASSOCIATORS OF " +
                "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
                "WHERE AssocClass = Win32_DiskDriveToDiskPartition"
  Get-WmiObject -Query $partitions | ForEach-Object {
    $partition = $_
    $drives = "ASSOCIATORS OF " +
              "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
              "WHERE AssocClass = Win32_LogicalDiskToPartition"
    Get-WmiObject -Query $drives | ForEach-Object {
      $driveLetter = $_.DeviceID
      $fltr        = "DriveLetter='$driveLetter'"
      New-Object -Type PSCustomObject -Property @{
        Disk        = $disk.DeviceID
        DriveLetter = $driveLetter
        VolumeName  = $_.VolumeName
        VolumeID    = Get-WmiObject -Class Win32_Volume -Filter $fltr |
                      Select-Object -Expand DeviceID
      }
    }
  }
}

否则,它使用WMI似乎无法实现

在Windows 8 / Server 2012或更高版本上,您可以使用 获取分区 cmdlet,

On Windows 8/Server 2012 or newer you could use the Get-Partition cmdlet, though:

Get-Partition | Select-Object DiskNumber, DriveLetter, @{n='VolumeID';e={
  $_.AccessPaths | Where-Object { $_ -like '\\?\volume*' }
}}

这篇关于将物理设备ID与卷设备ID相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆