Use PowerShell to Mount ISO Files in Windows 8

Use PowerShell to Mount ISO Files in Windows 8

  • Comments 11
  • Likes

Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell 3.0 to mount ISO files in Windows 8. 

Microsoft Scripting Guy, Ed Wilson, is here. One of the things I love about interacting with the community is that I always come away with something. At times, it is a scenario where an IT Pro is attempting to do something, and the available Windows PowerShell cmdlets do not make the scenario easy. These become great ideas for Hey, Scripting Guy! Blog posts. At other times, I learn something. I do not know everything about everything—no one does. In fact, I consider it to be the mark of a true professional when they admit that they do not know everything about everything. Certainly, in working with Windows PowerShell 3.0 in Windows 8 and Windows Server 2012, no one knows everything. Dude, I do not even have the names of all the cmdlets memorized—there is a lot to learn.

So, the other night at the Windows PowerShell User Group meeting in Charlotte, North Carolina, I hit a trifecta. I picked up a really cool scenario, and I learned two really cool things. The PowerTip and the cmdlets that I talk about today are things I learned about. The scenario? Well, it is a bit more complicated, and I will need to spend some time working on it—but you will like it! Oh, by the way, the Windows PowerShell Saturday event in Atlanta, Georgia, is October 27 (the day after Windows Surface is available). Tickets are still available, and this will be an awesome event. I have seen some of the presentations (at the Windows PowerShell Saturday in Charlotte), and it will be an information-packed day.

By using Windows PowerShell 3.0 in Windows 8 and Windows Server 2012, the ability to mount an ISO file is built right in. No non-Microsoft utilities are required, nor are complex Win32 APIs involved—it’s all built into the Storage module. To use Windows PowerShell to mount an ISO image, all that is required is to call the Mount-DiskImage cmdlet and supply a full path to the ISO image.

Note   In Windows 8, administrative rights are required to mount a VHD, but not to mount an ISO image. In Windows Server 2012, admin rights are required to mount both a VHD and an ISO image.

On my computer, I have a folder called Bits that contains ISO images for various builds of Windows 8, Windows Server 2012, and SQL Server 2012. I want to mount all of these ISO images at the same time. Here is the command I use.

PS C:\bits> dir -Filter *.iso | % {mount-DiskImage -ImagePath $_.fullname}

I pop over to Windows Explorer, and sure enough, all of the ISO images are mounted. This is shown in the image that follows.

Image of menu

I can find out about the mounted drives by using the Get-DiskImage cmdlet as shown here.

PS C:\bits> dir -Filter *.iso | % {get-DiskImage -ImagePath $_.fullname}

 

Attached          : True

BlockSize         : 0

DevicePath        : \\.\CDROM1

FileSize          : 3490564096

ImagePath         : C:\bits\9200.16384.WIN8_RTM.120725-1247_X64FRE_ENTERPRISE_EVAL_E

                    N-US-HRM_CENA_X64FREE_EN-US_DV5.ISO

LogicalSectorSize : 2048

Number            : 1

Size              : 3490564096

StorageType       : 1

PSComputerName    :

<output truncated>

I can find volume information about the mounted ISO images by using the Get-Volume cmdlet. This is shown here.

PS C:\bits> dir -Filter *.iso | % {get-DiskImage -ImagePath $_.fullname} | get-volume

 

DriveLetter  FileSystemL FileSystem  DriveType   HealthStatu SizeRemaini        Size

             abel                                s                    ng

-----------  ----------- ----------  ---------   ----------- -----------        ----

E            HRM_CENA... UDF         CD-ROM      Healthy             0 B     3.25 GB

F            HRM_SSS_... UDF         CD-ROM      Healthy             0 B     3.44 GB

G            HRM_SSS_... UDF         CD-ROM      Healthy             0 B     3.44 GB

H            HRM_CENA... UDF         CD-ROM      Healthy             0 B     2.38 GB

I            SQLFULL_ENU CDFS        CD-ROM      Healthy             0 B      4.2 GB

J            HRM_CENA... UDF         CD-ROM      Healthy             0 B     2.38 GB

K            HRM_CCSA... UDF         CD-ROM      Healthy             0 B     3.34 GB

If I attempt to find disk information, however, an error arises (unless I am running with administrative rights). This error states, “CIM resource was not available,” which is somewhat misleading. I need to look in the CategoryInfo portion of the error to see that it was a PermissionDenied error. This is shown in the image that follows.

Image of command output

After I open Windows PowerShell as an administrator, and I attempt to run the command again, I still do not find the disk information. I get an “object not found” error. It appears that mounted ISO drives do not register as physical disk drives, but they do register as disk volumes.

I can get a directory listing from each of the drives by using the following command (the command is broken at the pipe character to permit display on the blog).

PS C:\bits> (dir -Filter *.iso | % {get-DiskImage -ImagePath $_.fullname} |

Get-Volume).driveletter | % { sl "$_`:" ; gci }

To dismount the disks, use the following command.

dir -Filter *.iso | % {get-DiskImage -ImagePath $_.fullname} | Dismount-DiskImage

That is all there is to using the mount and dismount disk image cmdlets. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Why do you encrypt your PowerShell Code ?

    | % { sl "$_`:" ; gci }

    If you want to do it right use Base64 !

  • Is the Storage module available for Windows 7/2008 R2 for Powershell 3?

  • @Peter Kriegel .... sorry. This is not encrypted, it is using PowerShell aliases. Here is the command syntax spelled out:

    | Foreach-Object { Set-Location "$_`:" ; Get-ChildItem }

  • @James Bryant not sure. I have not used Windows 7 or Windows Server 2008 R2 in a long time. I would guess that it is not available because it is using a lot of new providers that only exist in Windows 8 and Windows Server 2012 ... but that is only a guess. I do not have access to a Windows 7 or Windows 2008 R2 machine right now to test.

  • Hi,

    Just have a look to the way I propose to dismount any mounted drives without knowing the source of their ISO file

    p0w3rsh3ll.wordpress.com/.../mount-iso-files

  • @James Bryant I'm using PowerShell 3 on Windows 7. No, the Storage cmdlets aren't available. The API's to mount images in Windows 7 are also not available. I've created a couple wrapper scripts for PowerISO and MagicISO that I'm going to stick on my blog at some point.

  • James Bryant :

    Function        Mount-DiskImage     is  in   Storage module, but powershell 3.0 Lost half module in windows7!

    powershell 3.0 in windows 7 is Semi-finished products!

    powershell 3.0 in windows 8 is full version.

    --------------windows7-------------------

    c:\Windows\System32\WindowsPowerShell\v1.0\Modules\

    applocker

    bitstransfer

    cimcmdlets

    ise

    Microsoft.PowerShell.Diagnostics

    Microsoft.PowerShell.Host

    Microsoft.PowerShell.Management

    Microsoft.PowerShell.Security

    Microsoft.PowerShell.Utility

    Microsoft.WSMan.Management

    PSDiagnostics

    PSScheduledJob

    PSWorkflow

    PSWorkflowUtility

    TroubleshootingPack

    --------------windows8-------------------

    C:\Windows\System32\WindowsPowerShell\v1.0\Modules

    Appx

    BitLocker

    BranchCache

    CimCmdlets

    DirectAccessClientComponents

    Dism

    DnsClient

    International

    iSCSI

    ISE

    Kds

    Microsoft.PowerShell.Diagnostics

    Microsoft.PowerShell.Host

    Microsoft.PowerShell.Management

    Microsoft.PowerShell.Security

    Microsoft.PowerShell.Utility

    Microsoft.WSMan.Management

    MMAgent

    MsDtc

    NetAdapter

    NetConnection

    NetLbfo

    NetQos

    NetSecurity

    NetSwitchTeam

    NetTCPIP

    NetworkConnectivityStatus

    NetworkTransition

    PKI

    PrintManagement

    PSDiagnostics

    PSScheduledJob

    PSWorkflow

    PSWorkflowUtility

    ScheduledTasks

    SecureBoot

    SmbShare

    SmbWitness

    Storage

    TroubleshootingPack

    TrustedPlatformModule

    VpnClient

    Wdac

    WebAdministration

    WindowsDeveloperLicense

    WindowsErrorReporting

  • Is there a way to edit the ISO to replace files?

  • @Scott This method of mounting an ISO opens it up in a read / write fashion. I use this technique, to add files to an ISO.

  • An easy way to get mounted iso drive letter:

    $mountedISO = [string](Mount-DiskImage -ImagePath $_.fullname -Passthru | Get-DiskImage | Get-Volume).DriveLetter + ":\"

  • Windows is such a joke. Do you know how to mount an ISO on a real server operating system?
    If you're using a GUI file manager, you double click on the file.
    If you're using the command line (not the alternate command line or the power command line, just the only one that's needed): mount myisofile.iso /mnt/existingMountpoint


    No idiosyncratic command-lets. No secondary shell environments. No mysteries that you need to learn at user group meetings. No GUIDs to redirect from the output of one command into another. No Base64. It doesn't work one way on one version of the OS and another on the other. It's a standard command, implemented on multiple systems the same way for 20 years.

    Basic, common tasks should be easy to do.

    By the way
    dir -Filter *.iso | % {mount-DiskImage -ImagePath $_.fullname}
    Doesn't do squat on Windows Server 2008 R2
    mount-DiskImage doesn't exist.

    How do you all stand it? I work with windows 2 days in a row and I'm ready to quit my job.