I have seen some similar questions on this here on stack overflow, but I cannot get any of the answers to far to work.
I have this .ps1 file that mounts a drive and echos the drive letter (expected $driverLetter = "G" || "H" || "I"):
$mountDisk = Mount-DiskImage -ImagePath $args[0] -Passthru
$driveLetter = ($mountDisk | Get-Volume).DriveLetter
echo $driveLetter
I'm running it from this batch file:
FOR /F "usebackq delims=" %%i IN (`powershell -File ./mountDisk.ps1 "%1"`) DO SET "d=%%i"
Echo %d%
Each time I get an empty variable. I've tried setting environment variables, but yield same result.
%1. Whilst you think it may have been fine to omit it, is is absolutely possible that it would show the immediate reason.Get-Volumeonly works if your ImagePath was StorageType ISO, not VHD/VHDx etc. So the first thing you need to confirm is that you're passing an existing ISO file as the first argument to that PowerShell script. Also to useMount-DiskImageto mount a VHD file, as opposed to an ISO, administrator privileges are required...DO SET "d=%%i"to..do echo %%~i