Reputation: 65
I am looking to get the drive letter of the VHD mount using Powershell. I can mount the VHD with the below cmdlet:
Mount-VHD -Path d:/tmp.vhdx
The mount works fine, but when I try getting the drive letter:
Get-DiskImage -ImagePath d:\tmp.vhdx | Get-Disk | Get-Partition | Get-Volume ).DriveLetter
It fails with below error:
Get-DiskImage : Invalid property
I believe Get-DiskImage
works fine for an ISO, but not for VHD? Can you help me in obtaining it for VHD.
Upvotes: 5
Views: 13191
Reputation: 1382
This way work for me:
$DriveLetter = (Mount-VHD -Path "G:\YourVHDX.vhdx" -PassThru | Get-Disk | Get-Partition | Get-Volume).DriveLetter
Then Write-Output $DriveLetter
will show the drive letter.
Upvotes: 6
Reputation: 1
$DriveLetter = (Mount-VHD -Path "G:\YourVHDX.vhdx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object {$_.FileSystemLabel -like ""}).DriveLetter
Upvotes: 0