我正在尝试通过 PowerShell 使用 WMI 来运行远程服务器上的 SAN 存储,以获取 Windows 磁盘管理卷标。
我发现执行此操作的唯一方法是将卷设备 ID (\\?\Volume{34243...}
与物理磁盘设备 ID (\\.\PHYSICALDRIVE01
)。
但是,我一直无法找到如何将这两个字段链接在一起。这可以通过 WMI 实现吗?
最佳答案
对于分配了驱动器号的卷,您可以将磁盘和卷关联起来,如下所示:
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*' }
}}
关于powershell - 将物理设备 ID 与卷设备 ID 相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35878166/