How do I get the drive letter for the ISO I mounted with Mount-DiskImage
I found this to work
$beforeMount = (Get-Volume).DriveLetter
$mountResult = Mount-DiskImage $imagePath
$setuppath = (compare $beforeMount (Get-Volume).DriveLetter -PassThru) + ":\"
Try this:
$mountResult = Mount-DiskImage D:\ISOs\clonezilla-live-1.2.12-10-i486.iso -PassThru
$mountResult | Get-Volume
This will return which drive letter that ISO is assigned to along with other info -- from there it's just a matter of parsing the output.
EDIT: This will return JUST the drive letter:
$driveLetter = ($mountResult | Get-Volume).DriveLetter
FYI I had an issue mounting same image again so I made a small change, which checks if image is already mounted if not mounts and give the volume.
$ImagePath= " " ## Path of ISO image to be mounted
$ISODrive = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter
IF (!$ISODrive) {
Mount-DiskImage -ImagePath $ImagePath -StorageType ISO
}
$ISODrive = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter
Write-Host ("ISO Drive is " + $ISODrive)