powershellmount-diskimage

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


I have a batch file I'm executing on Windows 10 through the "Deployment and Imaging Tools Environment"

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

The environment variable WORKSPACE has been checked and contains a valid path that exists as does the file W10-LTSB.iso, however when this command is executed it results in:

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

Everything looks valid and has been checked many times, what does this message mean?


Solution

  • When a path starts with a dot/period ., it refers to the current directory. When a shell session starts, its current directory is configuration dependent.

    For example, try running a Powershell session. It should default in c:\Users\<username>. Run a Powershell as admin and it usually defaults in C:\WINDOWS\system32.

    When mounting a disk image with a path beginning with a dot

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

    will tell Mount-DiskImage to look the file from its current directory's subdir. Should the current directory be unexpected, Powershell's looking the file from wrong a place.

    As for a solution, use absolute paths, or make sure the file is located in a path that's available via current directory (whatever it is).