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.
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.
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