powershell Mount-DiskImage "The system cannot find the path specified."

powershelll Mount-DiskImage "The system cannot find the path specified."

我有一个正在 Windows 10 到 "Deployment and Imaging Tools Environment"

上执行的批处理文件
powershell Mount-DiskImage ./%WORKSPACE%/W10-LTSB.iso

环境变量 WORKSPACE 已被检查并包含一个有效路径,该路径与文件 W10-LTSB.iso 一样存在,但是当执行此命令时,它会导致:

Mount-DiskImage: The system cannot find the path specified.
At line:1 char:1
+ Mount-DiskImage ./CA20-4002-OperatingSystem-AIMB-216/W10-LTSB.iso
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_DiskImage:ROOT/Microsoft/.../MSFT_DiskImage) [Mount-DiskImage], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070003,Mount-DiskImage

一切看起来都有效并且已经过多次检查,这条消息是什么意思?

当路径以 dot/period . 开头时,它 refers to 当前目录。 shell 会话启动时,其当前目录取决于配置。

例如,尝试 运行 强力 shell 训练。它应该默认为 c:\Users\<username>。 运行 一个 Powershell 作为管理员并且它通常默认为 C:\WINDOWS\system32

挂载路径以点开头的磁盘映像时

powershell Mount-DiskImage ./%WORKSPACE%/W10-LTSB.iso

将告诉 Mount-DiskImage 从当前目录的子目录中查找文件。如果当前目录不正确,Powershell 会从错误的位置查找文件。

至于解决方案,请使用绝对路径,或确保文件位于通过当前目录(无论是什么)可用的路径中。