Refresh IoT Enterprise Installation Media

In this article, you set up your media refresh environment and gather all prerequisites that are required to update both the WinPE environment and the main operating system, install drivers

Prepare Media Servicing Environment

  1. Start PowerShell with Administrator privileges.
    We use this instance of PowerShell for the end to end process of servicing the installation media to apply updates and, if needed, incorporate required drivers that aren't part of the Windows installation media

    • Select Start
    • Type PowerShell
    • Right-click Windows PowerShell
    • Select Run as administrator
  2. Create folders to store files during media servicing
    Use the PowerShell command New_Item to create the following folders on your technician PC to store files needed during media servicing.

    c:\MediaRefresh: Parent folder for storing files during media servicing.
    c:\MediaRefresh\Out: Copy of the original media updated during servicing.
    c:\MediaRefresh\Packages\LCU: Latest Cumulative Update c:\MediaRefresh\Packages\SSU: Servicing Stack Update if necessary
    c:\MediaRefresh\Drivers: Third-party drivers.
    c:\MediaRefresh\Scripts: Custom install scripts. c:\MediaRefresh\WIM: Working directory for updating boot.wim and install.wim

    md c:\MediaRefresh\Drivers
    md c:\MediaRefresh\Out
    md c:\MediaRefresh\Packages\LCU
    md c:\MediaRefresh\Packages\SSU
    md c:\MediaRefresh\Scripts
    md c:\MediaRefresh\WIM
    
  3. Copy files from original media
    Copy all files from the original installation media to c:\MediaRefresh\Out.

    1. Proceed to step b. if you have physical media, otherwise you must first mount the Windows IoT Enterprise installation ISO using Mount-DiskImage and display the resulting mounted drive letter using Get-Volume.

      Mount-DiskImage -ImagePath <ISO Path> | Get-Volume
      

      Where <ISO Path> is a fully qualified path to your ISO

      Make note of the DriveLetter as we'll need to use it in the next step.

    2. Copy files from the original installation media denoted here by <DriveLetter> to c:\MediaRefresh\Out folder using Robocopy.

      robocopy <DriveLetter>:\ c:\MediaRefresh\Out /Copy:DT /e
      

      Where <DriveLetter> is the drive letter associated with the mounted ISO file

    3. Move boot.wim and install.wim from c:\MediaRefresh\Out\Sources to c:\MediaRefresh\WIM folder, the working folder for updating the WIM files, using Robocopy.

      robocopy c:\mediarefresh\out\sources c:\MediaRefresh\WIM *.wim /Mov
      
    4. Proceed to next step if you didn't mount an ISO for the previous command, otherwise you must first dismount the Windows IoT Enterprise installation ISO using Dismount-Diskimage

      Dismount-DiskImage -ImagePath <ISO Path>  
      

      Where <ISO Path> is a fully qualified path to your ISO file.

  4. Gather servicing packages

    Download the latest cumulative Microsoft Servicing Update (MSU) file to the c:\MediaRefresh\Packages\LCU folder.

    If a Servicing Stack Update (MSU) dependency is required, download it to c:\MediaRefresh\Packages\SSU folder. Use the following table to help you locate updates for your specific version of Windows IoT Enterprise.

    Release Version Update History Update Catalog
    Windows 11 IoT Enterprise LTSC 2024 [24H2] 26100 Show update history Show x64 updates
    Show Arm64 updates
    Windows 10 IoT Enterprise LTSC 2021 19044 Show update history Show x64 updates
    Show ARM64 updates
    Windows 10 IoT Enterprise LTSC 2019 17763 Show update history Show x64 updates
    Show ARM64 updates
    Windows 10 IoT Enterprise LTSC 2016 14393 Show update history Show x64 updates
    Show x86 updates
    Windows 10 IoT Enterprise LTSC 2015 10240 Show update history Show x64 updates
    Show x86 updates
  5. [Optional] Gather third party drivers
    Place the third-party drivers required for your device in an uncompressed format into the root of c:/MediaRefresh/drivers folder or as subfolders to c:/MediaRefresh/drivers.

  6. [Optional] Gather configuration scripts
    Place your Setupcomplete.cmd and ErrorHandler.cmd custom scripts that run during or after the Windows Setup process into the c:\MediaRefresh\Scripts folder.

    For more information, see Add a Custom Script to Windows Setup

Update Windows Preinstallation Environment (WinPE)

The Windows Preinstallation Environment (WinPE) is contained within boot.wim on the original installation media under the \sources folder. In this section, we walk through the process of updating the boot.wim with the latest cumulative servicing update and incorporate third party drivers if needed into the WinPE environment using the Media Servicing Environment.

  1. Mount WinPE boot.wim

    1. The first step in updating the WinPE environment is to create a temporary folder named mounted under c:\mediarefresh using the PowerShell command New-Item

      MD c:\MediaRefresh\mounted
      
    2. Before we can update the boot.wim, we need to make sure that its file attribute isn't set to ReadOnly. Use the PowerShell command Set-ItemProperty to remove the ReadOnly attribute.

      Set-ItemProperty -Path "c:\mediarefresh\wim\boot.wim" -Name IsReadOnly -Value $false
      
    3. Now we can mount the WinPE image stored in boot.wim at index 2 using the PowerShell command Mount-WindowsImage

      Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\boot.wim" -Index 2 -Path "c:\mediarefresh\Mounted"
      
    4. The contents of the WinPE image stored in the boot.wim at index 2 is now viewable at c:\mediarefresh\mounted.

  2. Apply third-party drivers to WinPE
    Install third-party drivers you collected in the c:\mediarefresh\drivers folder to WinPE at c:\mediarefresh\mounted using the PowerShell command Add-WindowsDriver.

    Note

    For testing purposes you can use -ForceUnsigned to add unsigned drivers and override the requirement that drivers must have a digital signature. For more information about driver signing requirements, see Device Drivers and Deployment Overview.

    Add-WindowsDriver -Path "c:\mediarefresh\Mounted" -Driver "c:\mediarefresh\drivers" -Recurse
    
  3. Apply servicing updates to WinPE
    Apply the latest cumulative update and its dependencies that you downloaded to c:\mediarefresh\packages folder to WinPE at c:\mediarefresh\mounted using the PowerShell command Add-WindowsPackage. This process may take several minutes to complete, however it ensures that your Windows image already has the latest servicing update applied.

    1. First apply the servicing stack update dependency.

      Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"
      
    2. Now apply the latest cumulative update.

      Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\LCU"
      

    Tip

    If you encounter error 0x800f0823, your servicing update may have a dependency that must be applied first. If you already downloaded its dependency, try running the above command a second time. If this does not resolve the issue you may need to download an additional prerequisite for your update.

    • Make note of the KB####### in the filename of the update in c:\mediarefresh\packages.
    • Search support.microsoft.com with the KB#######
    • Open the first topic that matches and search for the term "prerequisite".
    • Download any prerequisites mentioned and run the above command again. Note, you may need to run the command twice in order to allow the prerequisite to applied first.
    • Continue to next step once error has been resolved.
  4. Copy updated Setup.exe
    Before continuing copy the updated setup.exe from WinPE at c:\mediarefresh\mounted\sources to c:\mediarefresh\out\sources using Robocopy.

    1. First we need to remove the ReadOnly attribute on c:\mediarefresh\mounted\sources\setup.exe using the PowerShell command Set-ItemProperty.

      Set-ItemProperty -Path "c:\mediarefresh\out\sources\setup.exe" -Name IsReadOnly -Value $false
      
    2. Now we can copy setup.exe from c:\mediarefresh\mounted\sources to c:\mediarefresh\out\sources using Robocopy.

      robocopy c:\mediarefresh\mounted\sources c:\mediarefresh\out\sources setup.exe
      
  5. Dismount and save changes to WinPE

    To complete the servicing process, use the PowerShell command Dismount-WindowsImage to save the changes.

    Important

    Before executing the Dismount-WindowsImage command, make sure you do not have any File Explorer views or command windows that are viewing contents under c:\mediarefresh\mounted. Failure to do so will result in an error when attempting to dismount.

    Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save
    
  6. Delete temporary folder

    Upon successful dismounting of the boot.wim, now we can remove the temporary folder c:\mediarefresh\mounted using the PowerShell command Remove-Item

    RD c:\MediaRefresh\mounted
    
  7. Publish Boot.wim to out folder

    Now copy the updated boot.wim from c:\mediarefresh\wim to c:\mediarefresh\out\sources using Robocopy.

    robocopy c:\mediarefresh\wim c:\mediarefresh\out\sources boot.wim
    

The Windows Preinstall Environment (WinPE) stored as boot.wim and setup.exe both located under c:\mediarefresh\out\sources\ are fully updated.

Update Windows IoT Enterprise

The Windows IoT Enterprise image is contained within install.wim on the original installation media under the \sources folder. In the Prepare Media Servicing Environment section, we moved install.wim into a working folder. In this section, we walk through the process of updating the install.wim with the latest cumulative servicing update and incorporate third party drivers if needed by the target device using the Media Servicing Environment. Once the update is complete, split the install.wim into smaller *.swm files so that they can be copied to a flash drive formatted as FAT32.

  1. Mount the OS install.wim

    1. The first step in updating the WinPE environment is to create a temporary folder named mounted under c:\mediarefresh using the PowerShell command New-Item.

      MD c:\MediaRefresh\mounted
      
    2. Before we can update the install.wim, we need to make sure that its file attribute isn't set to ReadOnly. Use the PowerShell command Set-ItemProperty to remove the ReadOnly attribute.

      Set-ItemProperty -Path "c:\mediarefresh\wim\install.wim" -Name IsReadOnly -Value $false
      
    3. Now we can mount the Windows IoT Enterprise image stored in install.wim at index 2 using the PowerShell command Mount-WindowsImage

      Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\install.wim" -Index 2 -Path "c:\mediarefresh\Mounted"
      
    4. The contents of the Windows IoT Enterprise image store in install.wim at index 2 is now viewable at c:\mediarefresh\mounted.

  2. Install third-party drivers
    Install third-party drivers you collected in the c:\mediarefresh\drivers folder to the OS image at c:\mediarefresh\mounted using the PowerShell command Add-WindowsDriver. The -recurse parameter enables processing of subfolders.

    Add-WindowsDriver -Path "c:\mediarefresh\mounted" -Driver "c:\mediarefresh\drivers" -Recurse 
    

    Note

    For testing purposes you can use -ForceUnsigned to add unsigned drivers and override the requirement that drivers must have a digital signature. For more information about driver signing requirements, see Device Drivers and Deployment Overview.

  3. Add Custom Setup Scripts

    1. Before adding custom setup scripts to the OS image, first create a scripts folder under c:\mediarefresh\mounted\windows\setup\ using the PowerShell command New-Item.

      MD c:\mediarefresh\mounted\windows\setup\scripts
      
    2. Copy scripts from c:\mediarefresh\scripts to c:\mediarefresh\mounted\windows\setup\scripts using Robocopy.

      robocopy c:\mediarefresh\scripts c:\mediarefresh\mounted\windows\setup\scripts *.cmd
      
  4. Apply servicing packages to the OS image
    Apply the latest cumulative update and its dependencies that you downloaded to c:\mediarefresh\packages folder to WinPE at c:\mediarefresh\mounted using the PowerShell command Add-WindowsPackage.

    1. First apply the servicing stack update dependency.

      Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"
      
    2. Now apply the latest cumulative update.

      Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\LCU"
      

    Tip

    If you encounter error 0x800f0823, your servicing update may have a dependency that must be applied first. If you already downloaded its dependency, try running the above command a second time. If this does not resolve the issue you may need to download an additional prerequisite for your update.

    • Make note of the KB####### in the filename of the update in c:\mediarefresh\packages.
    • Search support.microsoft.com with the KB#######
    • Open the first topic that matches and search for the term "prerequisite".
    • Download any prerequisites mentioned and run the above command again. Note, you may need to run the command twice in order to allow the prerequisite to applied first.
    • Continue to next step once error has been resolved.
  5. Save and dismount updated install.wim
    To complete the servicing process use the PowerShell command Dismount-WindowsImage to save the changes.

    Important

    Before executing the Dismount-WindowsImage command, make sure you do not have any File Explorer views or command windows that are viewing contents under c:\mediarefresh\mounted. Failure to do so will result in an error when attempting to dismount.

    Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save
    
  6. Delete temporary folder mounted
    Upon successful dismounting of the boot.wim, now we can remove the temporary folder c:\mediarefresh\mounted using the PowerShell command Remove-Item

    RD c:\mediarefresh\mounted
    
  7. Split WIM to support FAT32 file system
    To ensure the new install.wim fits onto flash media formatted as FAT32, which has a maximum file size of 4 GB you split the Windows Image (install.wim) file into a set of smaller (.swm) files with a maximum size of 4000 MB using the PowerShell command Split-WindowsImage. The resulting *.swm files are written to the c:\mediarefresh\out\sources folder.

    Split-WindowsImage -ImagePath "c:\mediarefresh\wim\install.wim" -SplitImagePath "c:\mediarefresh\out\sources\install.swm" -FileSize 4000 -CheckIntegrity
    

The OS installation image, originally stored as install.wim, is now stored under c:\mediarefresh\out\sources\ as install.swm and install2.swm which setup uses as if they were the original install.wim.

Copy updated media to flash drive

If you haven't created a bootable flash drive, do so before continuing by following the steps to Install Windows from a flash drive.

The final step of creating your updated installation media is to copy the contents of c:\mediarefresh\out to your bootable flash drive using Robocopy.

robocopy c:\mediarefresh\out <DriveLetter>:\ /e

Where <DriveLetter> is the drive letter associated with your flash drive

Install Windows to the new device

  1. Connect the flash drive to your target device.

  2. Turn on the device and press the key that opens the boot-device selection menu for the computer, such as the Esc/F10/F12 keys. Select the option that boots the device from the flash drive.

    Windows Setup starts. Follow the instructions to install Windows

    Tip

    You may need to consult the device manufacturer instructions to configure it for booting from the flash drive it this process does not work on your device.

  3. Once the initial phase of Setup is complete and your device reboots, Setup may start again from the beginning. If Setup starts again, cancel Setup, and shut down the computer then remove the flash drive and turn on the device to continue with the next phase of Setup.

    Tip

    If, for some reason, you encounter an error during the Setup process, please see the following articles for troubleshooting guidance.

Full Script

This section contains a full script that performs each of the media servicing steps in succession automatically. Before using this script, you must complete the Prepare Media Servicing Environment section of this article. Once you're ready, copy the following PowerShell script to c:\mediarefresh\mediarefresh.ps1.

$LogFile = ".\MediaRefresh.log"
$LogDetail = ".\MediaRefreshDetail.log"

"================================================" >> $LogFile
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Starting MediaRefresh" >> $LogFile
"================================================" >> $LogFile
Write-Host "Updating Boot.wim" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Boot.wim Update Started" >> $LogFile
Write-Host "     Preparing to mount boot.wim" -ForegroundColor Blue

(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Checking for existing .\Mounted folder" >> $LogFile

if ( -not (Test-Path -Path 'c:\MediaRefresh\mounted' -PathType Container)) { 
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Create .\Mounted folder" >> $LogFile
   MD c:\MediaRefresh\mounted >> $LogDetail
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Created .\Mounted folder" >> $LogFile
   }
   else {
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     .\Mounted folder already existed" >> $LogFile 
   }

Write-Host "     Setting boot.wim file attributes to read-write" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Setting boot.wim file attributes to read-write" >> $LogFile
Set-ItemProperty -Path "c:\mediarefresh\wim\boot.wim" -Name IsReadOnly -Value $false | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Set boot.wim file attributes to read-write" >> $LogFile

Write-Host "     Mounting boot.wim" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Mount-WindowsImage boot.wim Started" >> $LogFile
Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\boot.wim" -Index 2 -Path "c:\mediarefresh\Mounted" >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Mount-WindowsImage boot.wim Completed" >> $LogFile

Write-Host "     Installing Drivers" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsDrivers to boot.wim Started" >> $LogFile
Add-WindowsDriver -Path "c:\mediarefresh\mounted" -Driver "c:\mediarefresh\drivers" -Recurse >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsDrivers to boot.wim Completed" >> $LogFile

Write-Host "     Installing Servicing Stack Update" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage SSU to boot.wim Started" >> $LogFile
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU" >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage SSU to boot.wim Completed" >> $LogFile

Write-Host "     Installing Latest Cumulative Update" -ForegroundColor Blue
Write-Host "          Note: This process may take several minutes to complete." -ForegroundColor Cyan
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage LCU to boot.wim Started" >> $LogFile
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\LCU" >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage LCU to boot.wim Completed" >> $LogFile

Write-Host "     Setting read-write attribute on \out\sources\setup.exe" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Setting \out\sources\setup.exe file attributes to read-write" >> $LogFile
Set-ItemProperty -Path "c:\mediarefresh\out\sources\setup.exe" -Name IsReadOnly -Value $false >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Set \out\sources\setup.exe file attributes to read-write" >> $LogFile

Write-Host "     Copying updated setup.exe to \out\sources" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Copy updated setup.exe to .\out\sources Started" >> $LogFile
robocopy c:\mediarefresh\mounted\sources c:\mediarefresh\out\sources setup.exe | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Copy updated setup.exe to .\out\sources Completed" >> $LogFile

Write-Host "     Saving and dismounting boot.wim" -ForegroundColor Blue
Write-Host "          Note: This process may take several minutes to complete." -ForegroundColor Cyan
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Dismount-WindowsImage boot.wim Started" >> $LogFile
Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save -CheckIntegrity -LogLevel 3 >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Dismount-WindowsImage boot.wim Completed" >> $LogFile

Write-Host "     Removing \Mounted folder" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Removing .\mounted folder" >> $LogFile
RD c:\mediarefresh\mounted | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     .\mounted folder removed" >> $LogFile

Write-Host "     Copying updated boot.wim to \out\sources" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Copy boot.wim to .\out\sources Started" >> $LogFile
robocopy c:\mediarefresh\wim c:\mediarefresh\out\sources boot.wim | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Copy boot.wim to .\out\sources Completed" >> $LogFile
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Boot.wim Update Completed" >> $LogFile
Write-Host "Updating Boot.wim Complete" -ForegroundColor Blue

Write-Host "Updating Install.wim" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Install.wim Update Started" >> $LogFile
Write-Host "     Preparing to mount install.wim" -ForegroundColor Blue

(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Checking for existing .\Mounted folder" >> $LogFile

if ( -not (Test-Path -Path 'c:\MediaRefresh\mounted' -PathType Container)) { 
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Create .\Mounted folder" >> $LogFile
   MD c:\MediaRefresh\mounted  >> $LogDetail
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Created .\Mounted folder" >> $LogFile
   }
   else {
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     .\Mounted folder already existed" >> $LogFile 
   }

Write-Host "     Setting read-write attribute on install.wim" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Setting install.wim file attributes to read-write" >> $LogFile
Set-ItemProperty -Path "c:\mediarefresh\wim\install.wim" -Name IsReadOnly -Value $false | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Set install.wim file attributes to read-write" >> $LogFile

Write-Host "     Mounting install.wim" -ForegroundColor Blue
Write-Host "          Note: This process may take several minutes to complete." -ForegroundColor Cyan
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Mount-WindowsImage install.wim Started" >> $LogFile
Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\install.wim" -Index 2 -Path "c:\mediarefresh\Mounted" >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Mount-WindowsImage install.wim Completed" >> $LogFile


Write-Host "     Installing Drivers" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsDrivers to install.wim Started" >> $LogFile
Add-WindowsDriver -Path "c:\mediarefresh\mounted" -Driver "c:\mediarefresh\drivers" -Recurse  >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsDrivers to install.wim Completed" >> $LogFile

Write-Host "     Creating folder \Windows\Setup\Scripts" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Checking for existing \windows\setup\scripts folder" >> $LogFile
if ( -not (Test-Path -Path 'c:\mediarefresh\mounted\windows\setup\scripts' -PathType Container)) {
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Create \windows\setup\scripts folder" >> $LogFile
   MD c:\mediarefresh\mounted\windows\setup\scripts >> $LogDetail
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Created \windows\setup\scripts folder" >> $LogFile
   }
   else {
   (get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     \windows\setup\scripts already existed" >> $LogFile 
   }

Write-Host "     Copying Scripts to \Windows\Setup\Scripts" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Copy scripts to \windows\setup\scripts Started" >> $LogFile
robocopy c:\mediarefresh\scripts c:\mediarefresh\mounted\windows\setup\scripts *.cmd | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Copy scripts to \windows\setup\scripts Completed" >> $LogFile

Write-Host "     Installing Servicing Stack Update" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage SSU to install.wim Started" >> $LogFile
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"  >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage SSU to install.wim Completed" >> $LogFile 

Write-Host "     Installing Latest Cumulative Update" -ForegroundColor Blue
Write-Host "          Note: This process may take several minutes to complete." -ForegroundColor Cyan
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage LCU to install.wim Started" >> $LogFile 
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\LCU" >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Add-WindowsPackage LCU to install.wim Completed" >> $LogFile 

Write-Host "     Saving and dismounting install.wim" -ForegroundColor Blue
Write-Host "          Note: This process may take several minutes to complete." -ForegroundColor Cyan
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Dismount-WindowsImage install.wim Started" >> $LogFile
Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save -CheckIntegrity -LogLevel 3 >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Dismount-WindowsImage install.wim Completed" >> $LogFile

Write-Host "     Removing \Mounted folder" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     Removing .\mounted folder" >> $LogFile
RD c:\mediarefresh\mounted | out-null
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " |     .\mounted folder removed" >> $LogFile

Write-Host "Updating Install.wim Complete" -ForegroundColor Blue
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Install.wim Update Completed" >> $LogFile

Write-Host "Splitting Install.wim" -ForegroundColor Blue
Write-Host "     Note: This process may take several minutes to complete." -ForegroundColor Cyan
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Split-WindowsImage Started" >> $LogFile
Split-WindowsImage -ImagePath "c:\mediarefresh\wim\install.wim" -SplitImagePath "c:\mediarefresh\out\sources\install.swm" -FileSize 4000 -CheckIntegrity >> $LogDetail
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " | Split-WindowsImage Completed" >> $LogFile

Write-Host "Update Complete" -ForegroundColor Blue
Write-Host "Copy contents of c:\mediarefresh\out to your flash drive" -ForegroundColor Blue

Other Resources