gpt4 book ai didi

windows - 在 PowerShell 中将位置设置为新安装的磁盘镜像失败

转载 作者:可可西里 更新时间:2023-11-01 11:51:25 26 4
gpt4 key购买 nike

我正在尝试在脚本的函数中运行以下代码:

$result = Mount-DiskImage -ImagePath $imagepath -PassThru
$driveLetter = ($result | Get-Volume).DriveLetter
Set-Location "$($driveLetter):"

但它经常因这个错误而失败:

  Set-Location : Cannot find drive. A drive with the name 'G' does not exist.
At C:\Users\Agent\BuildAgent\scripts\helpers.psm1:35 char:3
+ Set-Location "$($driveLetter):"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (G:String) [Set-Location], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

但在脚本终止后我可以更改驱动器,没问题。

这可能与时间有关,但在设置位置之前注入(inject) sleep (即使是大 sleep )也无济于事。

有人知道这个问题吗?

最佳答案

让我们都赞成 bug report .

然后,我想我有一个解决方法,可以手动将驱动器添加为新的 PSDrive .我想 New-PSDrive cmdlet 可以访问安装的驱动器,即使其他人不能。

$mount = Mount-DiskImage $isoPath -PassThru
$driveLetter = ($mount | Get-Volume).DriveLetter

# Have to use New-PSDrive so other cmdlets in this session can see the new drive
New-PSDrive -Name $driveLetter -PSProvider FileSystem -Root "$($driveLetter):\"

// ...do things...

Dismount-DiskImage $mount.ImagePath

关于windows - 在 PowerShell 中将位置设置为新安装的磁盘镜像失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28543885/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com