我希望使用 Powershell 获取 VHD 安装的驱动器号。我可以使用以下 cmdlet 挂载 VHD:
Mount-VHD -Path d:/tmp.vhdx
Run Code Online (Sandbox Code Playgroud)
安装工作正常,但是当我尝试获取驱动器号时:
Get-DiskImage -ImagePath d:\tmp.vhdx | Get-Disk | Get-Partition | Get-Volume ).DriveLetter
Run Code Online (Sandbox Code Playgroud)
它失败并出现以下错误:
Get-DiskImage:无效的属性
我相信Get-DiskImage对 ISO 工作正常,但不适用于 VHD?你能帮我获取它的 VHD。
这种方式对我有用:
$DriveLetter = (Mount-VHD -Path "G:\YourVHDX.vhdx" -PassThru | Get-Disk | Get-Partition | Get-Volume).DriveLetter
Run Code Online (Sandbox Code Playgroud)
然后Write-Output $DriveLetter将显示驱动器号。
小智 0
$DriveLetter = (Mount-VHD -Path "G:\YourVHDX.vhdx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object {$_.FileSystemLabel -like ""}).DriveLetter
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5973 次 |
| 最近记录: |