使用 PowerShell WMI 或 Diskpart 检测选定磁盘上已卸载的卷
如何将未安装卷链接到物理磁盘?
假设我需要在磁盘 3 上查找并安装已卸载的卷,编号为 Diskpart 或 WMIC 或 PowerShell WMI。如何使用脚本找出磁盘 3 的哪些卷未安装?或者,给定的未安装卷(没有驱动器盘符)驻留在哪个物理磁盘上?
卸载卷后,该卷不存在任何逻辑磁盘或安装点。我想可以使用 GetRelated
方法找到关系,但我找不到适合该任务的代码示例。
How do I link unmounted volumes to physical disks?
Say I need to find and mount unmounted volumes on disk 3 as numbered by Diskpart or WMIC, or PowerShell WMI. How do I find out, with a script, what volumes of disk 3 aren't mounted? Or, alternatively, what physical disk a given unmounted volume (having no DriveLetter) resides on?
When a volume is unmounted, no logical disk or mount point exist for it. I suppose the relation can be found with GetRelated
method, but I can't find such a code example suited for the task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下,它将:
$targetDisk
的所有已卸载分区 使用使用
GetRelated
方法就是为了了解您需要关联的内容。它有助于了解 WMI 类代表您正在寻找的Win32_DiskPartition
。在您的情况下,您想要查找未与逻辑磁盘(已卸载)关联的分区,因此我们会查找没有关联的Win32_LogicalDisk
的Win32_DiskPartition
实例。由于您只想在特定物理磁盘上卸载卷,因此我们需要进一步关联类。为此,我们需要获取
Win32_DiskPartition
关联的Win32_DiskDrive
实例。Give this a try, it will:
$targetDisk
using WMIUsing the
GetRelated
method is all about knowing what you need to relate. It helps to know what WMI class represents what you are looking forWin32_DiskPartition
. In your case you want to find the partitions which are not associated with a logical disk (unmounted) so we look for instances ofWin32_DiskPartition
which don't have an associatedWin32_LogicalDisk
.Since you only want unmounted volumes on a particular physical disk we need to further associate classes. To do this we need to get
Win32_DiskPartition
's associatedWin32_DiskDrive
instance.将此代码集成到上面的答案中:
它通过使用卷 DeviceID 而不是其 DriveLetter 在 Windows 7 PowerShell 中进行查找,并将卷与磁盘 3 相关联,如上面的答案所示。可以使用与上面类似的方法(AddMountPoint 或 Mount),但不使用 Diskpart。
Integrate this code into the above answer:
It looks in Windows 7 PowerShell by using the Volume DeviceID instead of its DriveLetter, and relating the Volume to Disk 3 as shown in the above answer. A similar approach (AddMountPoint or Mount) can be used as above, but without using Diskpart.