在 Azure VM 中使用 PowerShell 检索用于存储池的磁盘的 VHD

在 Azure VM 中使用 PowerShell 检索用于存储池的磁盘的 VHD

我想知道哪些 VHD 用于特定存储池。使用跨平台 CLI,我可以获取 LUN 和 blob 名称:

$ azure vm disk list testvm
info:    Executing command vm disk list
+ Fetching disk images                                                         
+ Getting virtual machines                                                     
+ Getting VM disks                                                             
data:    Lun  Size(GB)  Blob-Name                                         OS     
data:    ---  --------  ------------------------------------------------  -------
data:         128       testvm-testvm-os-1457591813350.vhd                Windows
data:    0    1023      testvm-disk1.vhd                                  
data:    1    1023      testvm-disk2.vhd                                  
data:    2    1023      testvm-disk3.vhd                                  
data:    3    1023      testvm-disk4.vhd

在使用设备管理器应用程序的存储池的 VM 中,我能够获取驱动器号、友好名称、磁盘大小、磁盘 ID(与 diskpart 报告的相同),并且在“详细信息”选项卡中,有列出 LUN 的电源关系的信息:

SCSI\Disk&Ven_Msft&Prod_Virtual_Disk\000003
SCSI\Disk&Ven_Msft&Prod_Virtual_Disk\000001
SCSI\Disk&Ven_Msft&Prod_Virtual_Disk\000002
SCSI\Disk&Ven_Msft&Prod_Virtual_Disk\000000

我现在正尝试通过 PowerShell 获取相同的信息,但我能找到的最好的信息是 VHD 的友好名称,但在这种情况下它不是很有用:

PS C:\Users\vpjtech> Get-StoragePool -FriendlyName Data | Get-PhysicalDisk

FriendlyName            CanPool                 OperationalStatus       HealthStatus            Usage                                     Size
------------            -------                 -----------------       ------------            -----                                     ----
PhysicalDisk2           False                   OK                      Healthy                 Auto-Select                         1022.25 GB
PhysicalDisk5           False                   OK                      Healthy                 Auto-Select                         1022.25 GB
PhysicalDisk3           False                   OK                      Healthy                 Auto-Select                         1022.25 GB
PhysicalDisk4           False                   OK                      Healthy                 Auto-Select                         1022.25 GB

使用 Get-WmiObject 我能够获取 LUN,但我不知道如何将此信息与存储池链接起来:

PS C:\Users\vpjtech> Get-WmiObject -Class Win32_SCSIControllerDevice

__GENUS             : 2
__CLASS             : Win32_SCSIControllerDevice
__SUPERCLASS        : CIM_ControlledBy
__DYNASTY           : CIM_Dependency
__RELPATH           : Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.DeviceID=\"ROOT\\\\SPACEPORT\
                      \\\0000\"",Dependent="\\\\TESTVM\\root\\cimv2:Win32_PnPEntity.DeviceID=\"STORAGE\\\\DISK\\\\{BED09DDF-E9A5-11E5-8
                      0C0-000D3A404FE8}\""
__PROPERTY_COUNT    : 7
__DERIVATION        : {CIM_ControlledBy, CIM_DeviceConnection, CIM_Dependency}
__SERVER            : TESTVM
__NAMESPACE         : root\cimv2
__PATH              : \\TESTVM\root\cimv2:Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.De
                      viceID=\"ROOT\\\\SPACEPORT\\\\0000\"",Dependent="\\\\TESTVM\\root\\cimv2:Win32_PnPEntity.DeviceID=\"STORAGE\\\\DI
                      SK\\\\{BED09DDF-E9A5-11E5-80C0-000D3A404FE8}\""
AccessState         : 
Antecedent          : \\TESTVM\root\cimv2:Win32_SCSIController.DeviceID="ROOT\\SPACEPORT\\0000"
Dependent           : \\TESTVM\root\cimv2:Win32_PnPEntity.DeviceID="STORAGE\\DISK\\{BED09DDF-E9A5-11E5-80C0-000D3A404FE8}"
NegotiatedDataWidth : 
NegotiatedSpeed     : 
NumberOfHardResets  : 
NumberOfSoftResets  : 
PSComputerName      : TESTVM

__GENUS             : 2
__CLASS             : Win32_SCSIControllerDevice
__SUPERCLASS        : CIM_ControlledBy
__DYNASTY           : CIM_Dependency
__RELPATH           : Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.DeviceID=\"VMBUS\\\\{BA6163D9
                      -04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TESTVM\\root\\cimv2:Win
                      32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000000\""
__PROPERTY_COUNT    : 7
__DERIVATION        : {CIM_ControlledBy, CIM_DeviceConnection, CIM_Dependency}
__SERVER            : TESTVM
__NAMESPACE         : root\cimv2
__PATH              : \\TESTVM\root\cimv2:Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.De
                      viceID=\"VMBUS\\\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TES
                      TVM\\root\\cimv2:Win32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000000\""
AccessState         : 
Antecedent          : \\TESTVM\root\cimv2:Win32_SCSIController.DeviceID="VMBUS\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\{F8B3781B-1E82-
                      4818-A1C3-63D806EC15BB}"
Dependent           : \\TESTVM\root\cimv2:Win32_PnPEntity.DeviceID="SCSI\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\000000"
NegotiatedDataWidth : 
NegotiatedSpeed     : 
NumberOfHardResets  : 
NumberOfSoftResets  : 
PSComputerName      : TESTVM

__GENUS             : 2
__CLASS             : Win32_SCSIControllerDevice
__SUPERCLASS        : CIM_ControlledBy
__DYNASTY           : CIM_Dependency
__RELPATH           : Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.DeviceID=\"VMBUS\\\\{BA6163D9
                      -04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TESTVM\\root\\cimv2:Win
                      32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000001\""
__PROPERTY_COUNT    : 7
__DERIVATION        : {CIM_ControlledBy, CIM_DeviceConnection, CIM_Dependency}
__SERVER            : TESTVM
__NAMESPACE         : root\cimv2
__PATH              : \\TESTVM\root\cimv2:Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.De
                      viceID=\"VMBUS\\\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TES
                      TVM\\root\\cimv2:Win32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000001\""
AccessState         : 
Antecedent          : \\TESTVM\root\cimv2:Win32_SCSIController.DeviceID="VMBUS\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\{F8B3781B-1E82-
                      4818-A1C3-63D806EC15BB}"
Dependent           : \\TESTVM\root\cimv2:Win32_PnPEntity.DeviceID="SCSI\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\000001"
NegotiatedDataWidth : 
NegotiatedSpeed     : 
NumberOfHardResets  : 
NumberOfSoftResets  : 
PSComputerName      : TESTVM

__GENUS             : 2
__CLASS             : Win32_SCSIControllerDevice
__SUPERCLASS        : CIM_ControlledBy
__DYNASTY           : CIM_Dependency
__RELPATH           : Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.DeviceID=\"VMBUS\\\\{BA6163D9
                      -04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TESTVM\\root\\cimv2:Win
                      32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000002\""
__PROPERTY_COUNT    : 7
__DERIVATION        : {CIM_ControlledBy, CIM_DeviceConnection, CIM_Dependency}
__SERVER            : TESTVM
__NAMESPACE         : root\cimv2
__PATH              : \\TESTVM\root\cimv2:Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.De
                      viceID=\"VMBUS\\\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TES
                      TVM\\root\\cimv2:Win32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000002\""
AccessState         : 
Antecedent          : \\TESTVM\root\cimv2:Win32_SCSIController.DeviceID="VMBUS\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\{F8B3781B-1E82-
                      4818-A1C3-63D806EC15BB}"
Dependent           : \\TESTVM\root\cimv2:Win32_PnPEntity.DeviceID="SCSI\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\000002"
NegotiatedDataWidth : 
NegotiatedSpeed     : 
NumberOfHardResets  : 
NumberOfSoftResets  : 
PSComputerName      : TESTVM

__GENUS             : 2
__CLASS             : Win32_SCSIControllerDevice
__SUPERCLASS        : CIM_ControlledBy
__DYNASTY           : CIM_Dependency
__RELPATH           : Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.DeviceID=\"VMBUS\\\\{BA6163D9
                      -04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TESTVM\\root\\cimv2:Win
                      32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000003\""
__PROPERTY_COUNT    : 7
__DERIVATION        : {CIM_ControlledBy, CIM_DeviceConnection, CIM_Dependency}
__SERVER            : TESTVM
__NAMESPACE         : root\cimv2
__PATH              : \\TESTVM\root\cimv2:Win32_SCSIControllerDevice.Antecedent="\\\\TESTVM\\root\\cimv2:Win32_SCSIController.De
                      viceID=\"VMBUS\\\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\\\{F8B3781B-1E82-4818-A1C3-63D806EC15BB}\"",Dependent="\\\\TES
                      TVM\\root\\cimv2:Win32_PnPEntity.DeviceID=\"SCSI\\\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\\\000003\""
AccessState         : 
Antecedent          : \\TESTVM\root\cimv2:Win32_SCSIController.DeviceID="VMBUS\\{BA6163D9-04A1-4D29-B605-72E2FFB1DC7F}\\{F8B3781B-1E82-
                      4818-A1C3-63D806EC15BB}"
Dependent           : \\TESTVM\root\cimv2:Win32_PnPEntity.DeviceID="SCSI\\DISK&VEN_MSFT&PROD_VIRTUAL_DISK\\000003"
NegotiatedDataWidth : 
NegotiatedSpeed     : 
NumberOfHardResets  : 
NumberOfSoftResets  : 
PSComputerName      : TESTVM

应该有办法,但我没能理解。

答案1

根据您的描述,我在我的实验室中进行了测试。也许您可以使用以下 cmdlet:

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.PNPDeviceID
        DriveLetter = $driveLetter
        VolumeName  = $_.VolumeName
        VolumeID    = Get-WmiObject -Class Win32_Volume -Filter $fltr |
                      Select-Object -Expand DeviceID
        Size        = $disk.Size
      } |ft -AutoSize
    }
  }
}

在此处输入图片描述 问候,

沃尔特

相关内容