共用方式為


重新整理IoT企業版安裝媒體

在本文中,您會設定媒體重新整理環境,並收集更新 WinPE 環境和主要操作系統所需的所有必要條件,安裝驅動程式

準備媒體服務環境

  1. 使用系統管理員許可權啟動 PowerShell。
    我們將此 PowerShell 實例用於維護安裝媒體的端對端程式,以套用更新,並視需要併入不屬於 Windows 安裝媒體的必要驅動程式

    • 選取 [啟動]
    • 輸入 PowerShell
    • 以滑鼠右鍵按兩下 Windows PowerShell
    • 選取 [以系統管理員身分執行]
  2. 建立資料夾以在媒體服務期間儲存盤案
    使用 PowerShell 命令 New_Item 在您的技術人員電腦上建立下列資料夾,以儲存媒體服務期間所需的檔案。

    c:\MediaRefresh:媒體服務期間儲存檔案的父資料夾。
    c:\MediaRefresh\Out:服務期間更新的原始媒體複本。
    c:\MediaRefresh\Packages\LCU:最新的累積更新 c:\MediaRefresh\Packages\SSU:視需要維護堆棧更新
    c:\MediaRefresh\Drivers:第三方驅動程式。
    c:\MediaRefresh\Scripts:自定義安裝腳本。 c:\MediaRefresh\WIM:用於更新 boot.wim 和 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. 從原始媒體複製檔案
    將所有檔案從原始安裝媒體複製到 c:\MediaRefresh\Out

    1. 如果您有實體媒體,請繼續進行步驟b.,否則您必須先使用 Mount-DiskImage 掛接 Windows IoT 企業版安裝 ISO,並使用 Get-Volume 顯示產生的掛接驅動器號

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

      其中 <ISO Path> 是 ISO 的完整路徑

      記下 DriveLetter,因為我們在下一個步驟中需要使用它。

    2. 使用 Robocopy 將檔案從此處<DriveLetter>c:\MediaRefresh\Out所表示的原始安裝媒體複製到資料夾。

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

      其中 <DriveLetter> 是與掛接 ISO 檔案相關聯的驅動器號

    3. 使用 Robocopy 將 boot.wim 和 install.wim 從 c:\MediaRefresh\Out\Sources 資料夾c:\MediaRefresh\WIM移至資料夾、用來更新 WIM 檔案的工作資料夾。

      robocopy c:\mediarefresh\out\sources c:\MediaRefresh\WIM *.wim /Mov
      
    4. 如果您未針對先前的命令掛接 ISO,請繼續進行下一個步驟,否則您必須先使用 Dismount-Diskimage 卸除 Windows IoT 企業版安裝 ISO

      Dismount-DiskImage -ImagePath <ISO Path>  
      

      其中 <ISO Path> 是 ISO 檔案的完整路徑。

  4. 收集服務套件

    將最新的累積Microsoft服務更新 (MSU) 檔案下載至 c:\MediaRefresh\Packages\LCU 資料夾。

    如果需要服務堆疊更新 (MSU) 相依性,請將它下載至 c:\MediaRefresh\Packages\SSU 資料夾。 使用下表可協助您找出特定 Windows IoT 企業版的更新。

    版本 版本 更新歷程記錄 更新目錄
    Windows 10 IoT 企業版 LTSC 2021 19044 顯示更新歷程記錄 顯示 x64 更新
    顯示 ARM64 更新
    Windows 10 IoT 企業版 LTSC 2019 17763 顯示更新歷程記錄 顯示 x64 更新
    顯示 ARM64 更新
    Windows 10 IoT 企業版 LTSC 2016 14393 顯示更新歷程記錄 顯示 x64 更新
    顯示 x86 更新
    Windows 10 IoT 企業版 LTSC 2015 10240 顯示更新歷程記錄 顯示 x64 更新
    顯示 x86 更新
  5. [選擇性]收集第三方驅動程式
    將裝置所需的第三方驅動程式,以未壓縮的格式放入資料夾的c:/MediaRefresh/drivers根目錄,或作為 子資料夾。c:/MediaRefresh/drivers

  6. [選擇性]收集組態腳本
    將 Windows 安裝程式期間或之後執行的 和 Setupcomplete.cmd ErrorHandler.cmd 自訂腳本放在 c:\MediaRefresh\Scripts 資料夾中。

    如需詳細資訊,請參閱 將自定義腳本新增至 Windows 安裝程式

更新 Windows 預安裝環境 (WinPE)

Windows 預安裝環境 (WinPE) 包含在 boot.wim 資料夾下的原始安裝媒體中 \sources 。 在本節中,我們會逐步解說使用最新的累積服務更新來更新 boot.wim 的程式,並視需要將第三方驅動程式納入 WinPE 環境,並使用 媒體服務環境

  1. 掛接 WinPE boot.wim

    1. 更新 WinPE 環境的第一個步驟是使用 PowerShell 命令 New-Item 建立名為 mountedc:\mediarefresh暫存資料夾

      MD c:\MediaRefresh\mounted
      
    2. 在可以更新 boot.wim之前,我們需要確定其檔案屬性未設定為 ReadOnly。 使用 PowerShell 命令 Set-ItemProperty 來移除 ReadOnly 屬性。

      Set-ItemProperty -Path "c:\mediarefresh\wim\boot.wim" -Name IsReadOnly -Value $false
      
    3. 現在,我們可以使用PowerShell命令 Mount-WindowsImage 掛接儲存在boot.wim索引 2 的 WinPE 映像

      Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\boot.wim" -Index 2 -Path "c:\mediarefresh\Mounted"
      
    4. 儲存在索引 2 的 boot.wim WinPE 映射內容現在可在 檢視。c:\mediarefresh\mounted

  2. 將第三方驅動程式套用至 WinPE
    使用 PowerShell 命令 Add-WindowsDriver,將您在資料夾中收集c:\mediarefresh\drivers的第三方驅動程式安裝至 WinPEc:\mediarefresh\mounted

    注意

    為了進行測試,您可以使用 -ForceUnsigned 來新增未簽署的驅動程式,並覆寫驅動程式必須具有數位簽名的需求。 如需驅動程序簽署需求的詳細資訊,請參閱 設備驅動器和部署概觀

    Add-WindowsDriver -Path "c:\mediarefresh\Mounted" -Driver "c:\mediarefresh\drivers" -Recurse
    
  3. 將服務更新套用至 WinPE
    使用 PowerShell 命令 Add-WindowsPackage,將您下載至資料夾的最新累積更新及其相依性套用至 c:\mediarefresh\packages WinPEc:\mediarefresh\mounted。 此程式可能需要幾分鐘的時間才能完成,但可確保您的 Windows 映射已套用最新的服務更新。

    1. 首先套用服務堆疊更新相依性。

      Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"
      
    2. 現在套用最新的累積更新。

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

    提示

    如果您遇到錯誤0x800f0823,您的服務更新可能具有必須先套用的相依性。 如果您已經下載其相依性,請嘗試第二次執行上述命令。 如果無法解決此問題,您可能需要下載更新的其他必要條件。

    • 記下 c:\mediarefresh\packages 中更新檔名中的 KB #######。
    • 使用 KB 搜尋 support.microsoft.com #######
    • 開啟符合的第一個主題,並搜尋「必要條件」一詞。
    • 下載上述任何必要條件,然後再次執行上述命令。 請注意,您可能需要執行命令兩次,才能先套用必要條件。
    • 一旦解決錯誤,請繼續進行下一個步驟。
  4. 已更新複本 Setup.exe
    繼續將 更新 setup.exe 從 WinPE c:\mediarefresh\mounted\sources c:\mediarefresh\out\sources 複製到使用 Robocopy 之前。

    1. 首先,我們需要使用 PowerShell 命令 Set-ItemProperty 移除 上的 c:\mediarefresh\mounted\sources\setup.exe ReadOnly 屬性。

      Set-ItemProperty -Path "c:\mediarefresh\out\sources\setup.exe" -Name IsReadOnly -Value $false
      
    2. 現在,我們可以從 c:\mediarefresh\out\sources c:\mediarefresh\mounted\sources 複製到setup.exe使用 Robocopy

      robocopy c:\mediarefresh\mounted\sources c:\mediarefresh\out\sources setup.exe
      
  5. 將變更卸除並儲存至 WinPE

    若要完成服務程式,請使用PowerShell命令 Dismount-WindowsImage 來儲存變更。

    重要

    在執行Dismount-WindowsImage命令之前,請確定您沒有任何 檔案總管 檢視或命令視窗在下c:\mediarefresh\mounted檢視內容。 若無法這麼做,在嘗試卸除時會導致錯誤。

    Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save
    
  6. 刪除暫存資料夾

    成功卸除 boot.wim 後,我們現在可以使用 PowerShell 命令 Remove-Item 移除暫存資料夾c:\mediarefresh\mounted

    RD c:\MediaRefresh\mounted
    
  7. 發佈 Boot.wimout 資料夾

    現在,使用 Robocopy 將更新boot.wim的 複製到 。c:\mediarefresh\wim c:\mediarefresh\out\sources

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

儲存為 boot.wimsetup.exe 的 Windows 預安裝環境 (WinPE) 已完全更新。c:\mediarefresh\out\sources\

更新 Windows IoT 企業版

Windows IoT 企業版映射包含在 install.wim 資料夾下的原始安裝媒體中 \sources 。 在 [ 準備媒體服務環境] 區段中,我們移至 install.wim 工作資料夾。 在本節中,我們會逐步解說使用最新的累積服務更新來更新 install.wim 的程式,並使用媒體服務環境來納入目標裝置所需的第三方驅動程式。 更新完成後,請將 分割 install.wim 成較小的 *.swm 檔案,以便將其複製到格式化為 FAT32 的快閃磁碟驅動器。

  1. 掛接 OS install.wim

    1. 更新 WinPE 環境的第一個步驟是使用 PowerShell 命令 New-Item 建立名為 mountedc:\mediarefresh暫存資料夾。

      MD c:\MediaRefresh\mounted
      
    2. 我們必須先確定其檔案屬性未設定為 ReadOnly,才能更新 install.wim。 使用 PowerShell 命令 Set-ItemProperty 來移除 ReadOnly 屬性。

      Set-ItemProperty -Path "c:\mediarefresh\wim\install.wim" -Name IsReadOnly -Value $false
      
    3. 現在,我們可以使用 PowerShell 命令 Mount-WindowsImage,在 index 2 掛接儲存在 install.wim 中的 Windows IoT 企業版映射

      Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\install.wim" -Index 2 -Path "c:\mediarefresh\Mounted"
      
    4. 在 index 2 的 install.wim 中,Windows IoT 企業版映射存放區的內容現在可在 檢視。c:\mediarefresh\mounted

  2. 安裝第三方驅動程式
    使用 PowerShell 命令 Add-WindowsDriver,將您在資料夾中收集c:\mediarefresh\drivers的第三方驅動程式安裝到 OS 映射c:\mediarefresh\mounted 參數 -recurse 會啟用子資料夾的處理。

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

    注意

    為了進行測試,您可以使用 -ForceUnsigned 來新增未簽署的驅動程式,並覆寫驅動程式必須具有數位簽名的需求。 如需驅動程序簽署需求的詳細資訊,請參閱 設備驅動器和部署概觀

  3. 新增自訂安裝文稿

    1. 將自定義安裝腳本新增至OS映像之前,請先使用PowerShell命令New-Item建立scriptsc:\mediarefresh\mounted\windows\setup\的資料夾。

      MD c:\mediarefresh\mounted\windows\setup\scripts
      
    2. 使用 Robocopy 將文稿從 c:\mediarefresh\scripts c:\mediarefresh\mounted\windows\setup\scripts 複製到 。

      robocopy c:\mediarefresh\scripts c:\mediarefresh\mounted\windows\setup\scripts *.cmd
      
  4. 將服務套件套用至OS映像
    使用 PowerShell 命令 Add-WindowsPackage,將您下載至資料夾的最新累積更新及其相依性套用至 c:\mediarefresh\packages WinPEc:\mediarefresh\mounted

    1. 首先套用服務堆疊更新相依性。

      Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"
      
    2. 現在套用最新的累積更新。

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

    提示

    如果您遇到錯誤0x800f0823,您的服務更新可能具有必須先套用的相依性。 如果您已經下載其相依性,請嘗試第二次執行上述命令。 如果無法解決此問題,您可能需要下載更新的其他必要條件。

    • 記下 c:\mediarefresh\packages 中更新檔名中的 KB #######。
    • 使用 KB 搜尋 support.microsoft.com #######
    • 開啟符合的第一個主題,並搜尋「必要條件」一詞。
    • 下載上述任何必要條件,然後再次執行上述命令。 請注意,您可能需要執行命令兩次,才能先套用必要條件。
    • 一旦解決錯誤,請繼續進行下一個步驟。
  5. 儲存和卸除更新的install.wim
    若要完成維護程式,請使用PowerShell命令 Dismount-WindowsImage 來儲存變更。

    重要

    在執行Dismount-WindowsImage命令之前,請確定您沒有任何檢視在 下c:\mediarefresh\mounted檢視內容的 檔案總管 檢視或命令視窗。 若無法這麼做,在嘗試卸除時會導致錯誤。

    Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save
    
  6. 刪除暫存資料夾 mounted
    成功卸除 boot.wim 後,我們現在可以使用 PowerShell 命令 Remove-Item 移除暫存資料夾c:\mediarefresh\mounted

    RD c:\mediarefresh\mounted
    
  7. 分割 WIM 以支援 FAT32 檔案系統
    為了確保新的 install.wim 適用於格式化為 FAT32 的快閃媒體,其檔案大小上限為 4 GB,您可以使用 PowerShell 命令 Split-WindowsImage 將 Windows 映射 (install.wim) 檔案分割成一組較小的 (.swm) 檔案,其大小上限為 4000 MB。 產生的 *.swm 檔案會寫入 c:\mediarefresh\out\sources 資料夾。

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

原本儲存為install.wim的 OS 安裝映像現在會儲存在 as install.swm 底下c:\mediarefresh\out\sources\,而install2.swm哪個安裝程式會使用 ,就像是原始 install.wim的 。

將更新的媒體複製到快閃磁碟驅動器

如果您尚未建立可開機快閃磁碟驅動器,請先執行下列步驟,從 快閃磁碟驅動器安裝 Windows。

建立更新安裝媒體的最後一個步驟是使用 Robocopy 將 的內容c:\mediarefresh\out複製到可開機快閃磁碟驅動器。

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

其中 <DriveLetter> 是與您的快閃磁碟驅動器相關聯的驅動器號

將 Windows 安裝到新裝置

  1. 將快閃磁碟驅動器連線到您的目標裝置。

  2. 開啟裝置,然後按下開啟計算機的開機裝置選取功能表的按鍵,例如 Esc/F10/F12 鍵。 選取從快閃磁碟驅動器開機裝置的選項。

    Windows 安裝程式隨即啟動。 依照指示安裝 Windows

    提示

    您可能需要參閱裝置製造商指示,以將其設定為從快閃磁碟驅動器開機,此程式無法在您的裝置上運作。

  3. 安裝程式的初始階段完成且您的裝置重新啟動后,安裝程式可能會從頭重新啟動。 如果安裝程式再次啟動,請取消安裝程式,然後關閉計算機,然後移除快閃磁碟驅動器,然後開啟裝置以繼續進行下一個階段的安裝程式。

    提示

    如果基於某些原因,您在安裝程序期間遇到錯誤,請參閱下列文章以取得疑難解答指引。

完整腳本

本節包含完整腳本,可連續執行每個媒體維護步驟。 使用此腳本之前,您必須先完成 本文的準備媒體服務環境 一節。 準備好之後,請將下列 PowerShell 腳本複製到 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

其他資源