2016-03-08 68 views
3

我試圖通過PowerShell利用WMI運行遠程服務器上的SAN存儲以獲取Windows磁盤管理卷標。將物理設備ID關聯到卷設備ID

我發現做到這一點的唯一方法是卷設備ID(\\?\Volume{34243...}與物理磁盤設備ID(\\.\PHYSICALDRIVE01)相關。

不過,我一直無法找出如何這兩個領域連接在一起這可能與WMI

回答

1

對於被分配一個盤符,你可以像這樣的關聯磁盤和卷的卷:?

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 
     } 
    } 
    } 
} 

否則doesn't seem possible with WMI

在Windows 8/Server 2012中或更高版本,你可以使用Get-Partition cmdlet的,雖然:

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

有問題的服務器2008 R2,有幾個驅動器號,但一些重分析點。因此,我對分區類的初步評論並不是將其他類連接在一起的鏈接。 – Galvatron

+0

請參閱參考文章。 –