简体   繁体   English

通过 Powershell 使用驱动器号挂载 ISO

[英]Mount ISO with a drive letter via Powershell

I am trying to mount an ISO and I would like to associate a drive letter with that mount.我正在尝试挂载 ISO,并且想将驱动器号与该挂载相关联。 I would like to specify the drive letter as say Y:\ The below does not work, can anyone help me out.我想将驱动器号指定为 Y:\ 以下不起作用,谁能帮帮我。 Thanks谢谢

#Variable Declaration
$isoImg = "P:\Software\Windows10CurrentVersion\Windows10.iso"

#Mount ISO and Gather Drive Letter
Mount-DiskImage -ImagePath $isoImg -PassThru | Out-Null

#Obtain Drive Letter
$driveletter = (Get-DiskImage $isoImg | Get-Volume).DriveLetter

You could mount the ISO and accept (for now) the automatically assigned drive letter.您可以安装 ISO 并接受(暂时)自动分配的驱动器号。 It is possible to change that afterwards, but you will need to run that as Administrator:之后可以更改它,但您需要以管理员身份运行它:

# the full path to the ISO file
$isoPath = "P:\Software\Windows10CurrentVersion\Windows10.iso"

# mount the ISO, but first check if it is already mounted
$isoDrive = Get-DiskImage -ImagePath $isoPath
if (!$isoDrive) {
    $isoDrive = Mount-DiskImage -ImagePath $isoPath -PassThru
}
# $isoDrive is a Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_DiskImage

# get the DriveLetter currently assigned to the drive (a single [char])
$isoLetter = ($isoDrive | Get-Volume).DriveLetter

Rename the driveletter for this drive.重命名此驱动器的驱动器号。
This part needs to be run as Administrator这部分需要以管理员身份运行

# find the volume by its automatically assigned driveletter and set the new drive letter
$drive = Get-WmiObject Win32_Volume -Filter ('DriveLetter = "{0}:"' -f $isoLetter)
$drive.DriveLetter = 'Y:'
$null = $drive.Put()

To dismount the iso drive:要卸载 iso 驱动器:

$isoDrive | Dismount-DiskImage | Out-Null

Hope that helps希望有帮助

You can mount the ISO image and then assign the drive letter like this:您可以挂载 ISO 映像,然后像这样分配驱动器号:

# ISO image - replace with path to ISO to be mounted
$isoImg = "P:\Software\Windows10CurrentVersion\Windows10.iso"

# Drive letter - use the required drive letter instead of Y:
$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-Disk | Get-Partition | Get-Volume

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM