Powershell和WMI,如何将逻辑磁盘/卷映射到硬盘,反之亦然? [英] Powershell and wmi, how to map logical disk/volumes to a hard disk or vice versa?

查看:124
本文介绍了Powershell和WMI,如何将逻辑磁盘/卷映射到硬盘,反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Get-WmiObject -ComputerName $ip -Credential $credential -Class Win32_logicaldisk

这使我得到磁盘,如在我的电脑中看到的那样。 C :, D :, E:
现在如何获得相应的基础物理磁盘?

This gets me disks as I see them in "My computer", eg. C:, D:, E: Now how I get corresponding underlying physical disks ?

如果我按照以下命令运行

If I run following command

Get-WmiObject -ComputerName $ip -Credential $credential -Class win32_diskdrive

我得到磁盘0,磁盘1,磁盘2

I get disk 0, disk 1, disk 2

那么如何找出哪个逻辑磁盘位于哪个物理磁盘上?

So how to find out which logical disk is on which physical disk ?

另一个问题是如何找出卷号?如果我运行diskpart并执行列表卷,则会得到以下输出

Another question is how to find out volume number ? If I run diskpart and executes "list volume" I get the following output

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 2     C                NTFS   Partition     59 GB  Healthy    Boot
  ...

我如何找出逻辑磁盘C:是卷2?

How can I find out that logical disk C: is Volume 2 ?

最好的问候,Primoz。

best regards, Primoz.

推荐答案

尝试一下

Get-WMIObject Win32_LogicalDisk | Foreach-Object {
    Get-WmiObject -Query "Associators of {Win32_LogicalDisk.DeviceID='$($_.DeviceID)'} WHERE ResultRole=Antecedent"
} | Format-Table

这为您提供了WIn32_logicalDisk的相关实例,其中Win32_LogicalDisk是关系中的从属实体。因此,您将获得Win32_DiskDrive实例。

This gives you the related instances of WIn32_logicalDisk where Win32_LogicalDisk is the dependent entity in the relationship. So, you get the Win32_DiskDrive instances.

这篇关于Powershell和WMI,如何将逻辑磁盘/卷映射到硬盘,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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