New-ISOFile function

This PowerShell function uses IMAPI COM objects to create .iso files. Bootable images can also be created by using efisys.bin file, which can be found in Windows ADK.

 
 
 
 
 
4.5 Star
(34)
Add to favorites
Storage
3/25/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Hidden files
    1 Posts | Last post November 19, 2019
    • Any tip to include hidden folders / files? Example, c:\users\user\appdata
  • script does not work for me
    2 Posts | Last post October 15, 2019
    • when I run this script, it runs for a second without any error and at the end no ISO file created
      ran it like this: New-ISOfile "c:\temp\Drivers" 
      
    • The iso should be in your temp folder.  If you want to specify a path, use the -path option.
  • ESXi Media
    5 Posts | Last post October 12, 2019
    • Hello, I would be very interested to know if this could create ESXi bootable media. So far my iso fails to boot with "image checksum error". The ability to create custom images as part of a scripted build would be very useful to me :)
    • Couldn't get this function to make a bootable ESXi image so I tried cdrTools which includes a Windows version of mkisofs (on SourceForge).  Basically used the same command line string as in the VMware documentation.
      
      & .\mkisofs.exe -l -J -R -r -T -o $isoTarget -b ISOLINUX.BIN -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table $ScriptPath\isoFiles\ > null 2>&1
      
      This will direct all the output to null since Out-Null and standard redirection ">" didn't work.  
      
      BTW - I use 7-Zip CLI (7z.exe) to get the contents of the ISO:
      
      & .\7z.exe x -tiso $isoSource -o"$isoFiles" | Out-Null
      
      Hope it helps!
      
    • We're trying to do the same thing...looks like I'll be using mkisofs.exe after all...this would be a very elegant solution if it worked all natively in powershell.
    • This worked for me on Win2012r2 when creating an ESXi iso with custom boot.cfg.  I started by copying the contents of a regular ESXi iso into a folder, and then ran:
      
      dir .\ESXi | New-ISOFile -path .\esxi.iso -bootfile .\ESXi\ISOLINUX.BIN
      
      The iso was used directly via iDRAC virtual media.
    • I apparently got lucky with my first attempt.
      
      Isolinux.bin includes some info within the first 64 bytes of the file:
      offset 8: LBA of primary volume descriptor (4 bytes)
      offset 12: LBA of boot file (4 bytes)
      offset 16: Boot file length (4 bytes)
      offset 20: checksum (4 bytes) - this is generated starting at byte offset 64
      
      If you're editing an iso, only the LBAs will change.  If you force ISO9660 (IMAPI prefers UDF), with the following line, the values should be 16 and 20 for the LBAs:
      $Image.FileSystemsToCreate = 1 #FsiFileSystemISO9660
      
      You can also set offset 12 to 0, in which case isolinux will "hope and pray" that it's the first bootloader
      
      To do the editing within the New-IsoFile function, you'll want the following lines following the creation of $Image:
      If ($BootFile -match "isolinux"){
          $Image.FileSystemsToCreate = 1 #FsiFileSystemISO9660
          [byte[]] $bytes = 16,0,0,0,20,0,0,0 #or 16,0,0,0,0,0,0,0
          $Stream.Position = 8
          $Stream.Write($bytes)
          $Stream.AssignBootImage($Stream)
      }
      
      Once I figure out how to determine on the fly where the file is actually stored, I'll be contacting Chris Wu with the updated code.
  • how to use it
    2 Posts | Last post September 12, 2019
    • I had some trouble to make it works but if it can help someone:
      1) copy the function in a new .ps1 file
      2) at the very bottom (below the last }) write this and change the 2 paths according to your project ( C:\Users\user\Desktop\folderA\folderB should the files ex: AUTORUN.INF, MEDIA.INI):
      
      dir C:\Users\user\Desktop\folderA\folderB| New-IsoFile -Path C:\Users\user\Desktop\folderA\myiso.iso
      
      
      3) double click on the .ps1 file (the script took less than  second to create an iso from a 150MB folder)
      
      Thanks for sharing this script!
      
      I am on Windows 10
      
    • Also, it's not bootable, so to run it, simply open AUTORUN.INF and follow the links.
      
  • porting to C#
    1 Posts | Last post August 17, 2019
    • I am trying to port this function to C# so I can use It in my C# projects. But for some reason I get stuck.  Can anybody help me to point me in the right direction.
      I have referenced the ADODB from nugets. the IMAPI2FS.DLL  from c:\windows\system32.   The error i got is that the file could't not be found when calling the new class(title) constructor.
      
      
      using System;
      using IMAPI2FS;
      using ADODB;
      using ComTypes = System.Runtime.InteropServices.ComTypes;
      
      namespace IsoBuilder_Test
      {
          class Iso
          {
              ADODB.Stream _stream;
              BootOptions _boot;
              MsftFileSystemImage _image;
              IFileSystemImageResult _result;
      
              private Iso() { }       
      
              public Iso(string title)
              {
                  _stream = new ADODB.Stream();
                  _stream.Type = StreamTypeEnum.adTypeBinary;
                  _stream.Open();
                  _stream.LoadFromFile(@"c:\temp\files\efi\microsoft\boot\efisys_noprompt.bin");
                  var fsiStream = (FsiStream)_stream;
                  _boot = new BootOptions();
                  _boot.AssignBootImage(fsiStream);
                  _image = new MsftFileSystemImage() { VolumeName = title };
                  _image.ChooseImageDefaultsForMediaType(
                      IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER);
                  _image.BootImageOptions = _boot;
                 _result = _image.CreateResultImage();
              }
              public unsafe void Create(string Path)
              {
                  var totalBlocks = _result.TotalBlocks;
                  using (var o = System.IO.File.OpenWrite(Path))
                  {
                      int bytes = 0;
                      byte[] buf = new byte[_result.BlockSize];
                      var ptr = (IntPtr)(&bytes);
                      var i = _result.ImageStream as ComTypes.IStream;
                      do
                      {
                          i.Read(buf, _result.BlockSize, ptr); o.Write(buf, 0, bytes);
                      } while (totalBlocks-- > 0);
                  }
              }
          }
      }
  • Error encountered writing to 'data' stash file
    2 Posts | Last post September 26, 2018
    • Hi,
      
      Thank you for this script, it seems to work brilliantly creating an ISO file for Server 2012 R2. However, when creating ISO files for Server 2016 and Windows 10 using the DVDPLUSRW_DUALLAYER media, I get the following error:
      
      Error encountered writing to 'data' stash file.
      
      Can anyone help?
      
      Thanks!
      
      
    • 3-4 comments bellow there is mention about ESXi media. It seems that this script does not work anymore. I would probably remove it from the gallery.
  • Error with Powershell 5.1.15063.674
    2 Posts | Last post February 13, 2018
    • Hello,
      I have updated the last my windows 10 OS and now i obtain the following error when I load the function :
      
      PS E:\ShareFolders\Powershell\Tools> . ".\New-isoFile.ps1"
      The script failed due to call depth overflow.
          + CategoryInfo          : InvalidOperation: (0:Int32) [], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : CallDepthOverflow
      
      help please
    • Case closed
  • New-ISOFile.ps1 fails in Windows 2016 Core
    2 Posts | Last post November 02, 2017
    • Hello,
      On Windows 2016 Core, I get REGDB_E_CLASSNOTREG for IMAPI2FS.MsftFileSystemImage. Is there any workaround?
      
      The script works fine on Windows 2016 Desktop experience.
      
      Thanks!
    • I have the same issue
  • No Question, I just love it
    1 Posts | Last post July 17, 2017
    • Thanks for the script, saved my bacon more than once!
  • Enabling multi-boot ISO (Legacy & UEFI)
    1 Posts | Last post March 08, 2017
    • Has anyone ever tried modifying this to enable creation of a multi-boot ISO, such as Windows install media that boots from either etfsboot.com or efisys.bin? I tried just adding an additional -Bootfile switch and also tried adding the second boot file as a second parameter value, but the function did not allow for that.
1 - 10 of 17 Items