Peter Hinchley

Learning in Public

✪ Update an ISO using PowerShell

This short article demonstrates how to update an ISO using PowerShell. The script is specifically designed to modify the content of an ISO generated using the "offline task sequence media" capability in SCCM.

Have you ever waited for what seems like forever for SCCM to generate an ISO, and then you realise you screwed up, and there is an error in one of the software packages? You really don't want to have to regenerate the entire ISO in order to implement a simple fix. It happens to me frequently. Fortunately, you can save a lot of time by using this script to crack open the ISO and make the required change.

You should run this script on a computer with the ADK installed. Hopefully the code is self-explanatory.

# paths to media.
$media = 'c:\tasksequencemedia'
$old   = "$media\windows10.iso"
$new   = "$media\windows10-updated.iso"

# paths to tools.
$tools    = 'C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\oscdimg'
$oscdimg  = "$tools\oscdimg.exe"
$etfsboot = "$tools\etfsboot.com"
$efisys   = "$tools\efisys.bin"

# mount the existing iso.
$mount = mount-diskimage -imagepath $old -passthru

# get the drive letter assigned to the iso.
$drive = ($mount | get-volume).driveletter + ':'

# create a temp folder for extracting the existing iso.
$workspace = "{0}\{1}" -f $env:temp, [system.guid]::newguid().tostring().split('-')[0]
new-item -type directory -path $workspace

# extract the existing iso to the temporary folder.
copy-item $drive\* $workspace -force -recurse

# remove the read-only attribtue from the extracted files.
get-childitem $workspace -recurse | %{ if (! $_.psiscontainer) { $_.isreadonly = $false } }

# pause here... make manual updates to the extracted iso.
read-host

# create the updated iso.
$data = '2#p0,e,b"{0}"#pEF,e,b"{1}"' -f $etfsboot, $efisys
start-process $oscdimg -args @("-bootdata:$data",'-u2','-udfver102', $workspace, $new) -wait -nonewwindow

# remove the extracted content.
remove-item $workspace -recurse -force

# dismount the iso.
dismount-diskimage -imagepath $old