【问题标题】:Mount VHD and get drive letter挂载 VHD 并获取驱动器号
【发布时间】:2019-11-06 18:00:31
【问题描述】:

我希望使用 Powershell 获取 VHD 挂载的驱动器号。我可以使用以下 cmdlet 挂载 VHD:

Mount-VHD -Path d:/tmp.vhdx

挂载工作正常,但是当我尝试获取驱动器号时:

Get-DiskImage -ImagePath d:\tmp.vhdx | Get-Disk | Get-Partition | Get-Volume ).DriveLetter

失败并出现以下错误:

Get-DiskImage : 无效属性

我相信Get-DiskImage 适用于 ISO,但不适用于 VHD?你能帮我弄到 VHD 吗?

【问题讨论】:

  • $Volumes = Mount-VHD -Path d:\temp.vhdx -PassThru | Get-Disk | Get-Partition | Get-Volume See the help

标签: powershell


【解决方案1】:

这种方式对我有用:

$DriveLetter = (Mount-VHD -Path "G:\YourVHDX.vhdx" -PassThru | Get-Disk | Get-Partition | Get-Volume).DriveLetter

然后Write-Output $DriveLetter 将显示驱动器号。

【讨论】:

  • 对我来说这有时有效,但很多时候我收到一封空信,好像它还没有分配。不知道该怎么办...
【解决方案2】:
$DriveLetter = (Mount-VHD -Path "G:\YourVHDX.vhdx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object {$_.FileSystemLabel -like ""}).DriveLetter

【讨论】:

  • 在 Windows 10 上对我不起作用。Write-Output $DriveLetter 什么都不显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多