Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

55 lines (50 sloc) 2.41 KB
Extract and Configure SCCM WIM Boot Image
This script will extract the WIM file from the ISO boot image generated by SCCM. It then mounts, configures, and unmounts the WIM file so it is ready to push up to WDS.
Filename of the ISO, which includes the full path.
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.142
Created on: 8/21/2019 12:59 PM
Created by: Mick Pletcher
Filename: SCCMBootImage.ps1
[string]$File = 'C:\WinPE\SCCM.iso'
Import-Module Dism
#Extract the name of the directory the $File resides in
$Directory = $File.substring(0, $File.LastIndexOf('\'))
#Mount and assign drive letter
$Drive = ((Mount-DiskImage -ImagePath $File) | Get-Volume).DriveLetter
#Delete old Mount directory
Remove-Item -Path ($Directory + '\Mount') -Recurse -Force -ErrorAction SilentlyContinue
#Create Mount folder to copy WIM contents to
New-Item -Path ($Directory + '\Mount') -ItemType Directory -Force
#Delete old WIM file
Remove-Item -Path ($Directory + '\boot.wim') -ErrorAction SilentlyContinue -Force
#Copy boot.WIM file to $Directory
Copy-Item -Path ($Drive + ':\sources\boot.wim') -Destination $Directory -Force
#Turn off read only
Set-ItemProperty -Path ($Directory + '\boot.wim') -Name IsReadOnly -Value $false
#Mount the WIM file
Mount-WindowsImage -ImagePath ($Directory + '\boot.wim') -Index 1 -Path ($Directory + '\Mount')
#Copy data folder to mounted image
Copy-Item -Path ($Drive + ':\SMS\data') -Destination ($Directory + '\Mount\sms') -Recurse -Force
#Unmount Windows Image
Dismount-WindowsImage -Path ($Directory + '\Mount') -Save
#Dismount disk image
Dismount-DiskImage -ImagePath $File
#Delete the old wim if it exists
Remove-Item -Path ((Get-ChildItem -Path ($Directory + '\' + ((Get-ChildItem -path $File -ErrorAction SilentlyContinue).Basename) + '.wim')).FullName) -Force -ErrorAction SilentlyContinue
#Rename boot.wim to match the basename of the ISO
Rename-Item -Path ($Directory + '\boot.wim') -NewName ((Get-ChildItem -Path $File).BaseName + '.wim') -Force
#Delete the Mount folder
Remove-Item -Path ($Directory + '\Mount') -Recurse -Force -ErrorAction SilentlyContinue
You can’t perform that action at this time.