如何在Powershell中将ISO镜像挂载到指定盘符?

CJB*_*JBS 8 powershell mappeddrive iso drive-letters windows-10

我有一个想要安装的 ISO 映像(在本例中为 MS Office ISO)。

我想使用 Powershell,并在安装时指定驱动器号分配,以便我可以对已安装的 ISO(驱动器)上的文件使用脚本命令,之后我想卸载 ISO。

如何才能做到这一点?

背景:我想在给定 ISO 映像的情况下编写 MS Office 的安装脚本。

CJB*_*JBS 8

以下 Powershell 命令将把指定的 ISO 映像挂载到指定的驱动器盘符。mountvol命令需要提升权限,因此请以管理员身份运行 Powershell :

# 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  
Run Code Online (Sandbox Code Playgroud)

背景:这是一个有用的参考:https ://www.derekseaman.com/2010/04/change-volume-drive-letter-with.html