我尝试在我的脚本中的一个函数中运行以下代码:
$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但在脚本终止后,我可以更改驱动器,没有问题。
这可能与时间相关,但在设置位置之前插入睡眠(即使是较长的睡眠)也没有帮助。
有人知道这个问题吗?
发布于 2015-07-17 05:16:45
让我们一起为bug report投票吧。
然后,我想我可以通过手动将驱动器添加为新的PSDrive来解决此问题。我猜New-PSDrive cmdlet可以访问挂载的驱动器,尽管其他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发布于 2015-02-17 04:31:25
我不能尝试这样做,但是您的命令在我看来很奇怪--设置位置"$($driveLetter):“
你有没有试过设置位置"$driveLetter:“
不带花边
https://stackoverflow.com/questions/28543885
复制相似问题