How can an ISO image be mounted to a specified drive letter in Powershell?

I have an ISO image (in this case an MS Office ISO) that I'd like to mount.

I'd like to use Powershell, and specify the drive letter assignment at the time of mounting, such that I can use scripting commands on files on the mounted ISO (drive), after which time, I'd like to dismount the ISO.

How can this be done?

Background: I'd like to script installation of MS Office given an ISO image.


The following Powershell commands will mount the specified ISO image to the specified drive letter. The mountvol command requires elevation, so run Powershell as an Administrator:

# ISO image - replace with path to ISO to be mounted
$isoImg = "D:\en_visio_professional_2019_x86_x64_dvd_3b951cef.iso"
# Drive letter - use desired drive letter
$driveLetter = "Y:"

# Mount the ISO, without having a drive letter auto-assigned
$diskImg = Mount-DiskImage -ImagePath $isoImg  -NoDriveLetter

# Get mounted ISO volume
$volInfo = $diskImg | Get-Volume

# Mount volume with specified drive letter (requires Administrator access)
mountvol $driveLetter $volInfo.UniqueId

#
#
# Do work (e.g. MS Office installation - omitted for brevity)
#
#

# Unmount drive
DisMount-DiskImage -ImagePath $isoImg  

Background: this was a useful reference: https://www.derekseaman.com/2010/04/change-volume-drive-letter-with.html