刷新 IoT 企业版安装媒体
在本文中,你将设置媒体刷新环境,并收集更新 WinPE 环境和主操作系统所需的所有先决条件,安装驱动程序
准备媒体服务环境
使用管理员特权启动 PowerShell。
我们将此 PowerShell 实例用于维护安装媒体的端到端过程以安装更新,如果需要,请包含不属于 Windows 安装媒体的必需驱动程序- 选择“启动”
- 键入 PowerShell
- 右键单击“Windows PowerShell”
- 选择“以管理员身份运行”
在媒体服务期间创建用于存储文件的文件夹
使用 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
从原始媒体复制文件
将所有文件从原始安装媒体复制到c:\MediaRefresh\Out
。如果已有物理媒体,则继续执行步骤
b.
,否则必须先使用 Mount-DiskImage 装载 Windows IoT 企业版安装 ISO,并使用 Get-Volume 显示生成的装载驱动器号。Mount-DiskImage -ImagePath <ISO Path> | Get-Volume
其中
<ISO Path>
是 ISO 的完全限定路径记下 DriveLetter,因为我们需要在下一步使用它。
使用 Robocopy 将文件从此处由
<DriveLetter>
表示的原始安装媒体复制到c:\MediaRefresh\Out
文件夹。robocopy <DriveLetter>:\ c:\MediaRefresh\Out /Copy:DT /e
其中
<DriveLetter>
为与装载的 ISO 文件关联的驱动器号使用 Robocopy 将 boot.wim 和 install.wim 从
c:\MediaRefresh\Out\Sources
移动到c:\MediaRefresh\WIM
文件夹(用于更新 WIM 文件的工作文件夹)中。robocopy c:\mediarefresh\out\sources c:\MediaRefresh\WIM *.wim /Mov
如果没有为上一命令装载 ISO,则继续执行下一步,否则必须先使用 Dismount-Diskimage 卸载 Windows IoT Enterprise 安装 ISO
Dismount-DiskImage -ImagePath <ISO Path>
其中
<ISO Path>
是 ISO 文件的完全限定路径。
收集服务包
将最新的累积 Microsoft 服务更新 (MSU) 文件下载到
c:\MediaRefresh\Packages\LCU
文件夹中。如果需要服务堆栈更新 (MSU) 依赖项,请将其下载到
c:\MediaRefresh\Packages\SSU
文件夹。 使用下表帮助你查找特定版本的 Windows IoT 企业版的更新。版本 版本 更新历史记录 更新目录 Windows 11 IoT 企业版 LTSC 2024 [24H2] 26100 显示更新历史记录 显示 x64 更新
显示 ARM64 更新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 更新[可选] 收集第三方驱动程序
将设备所需的第三方驱动程序以未压缩的格式放入c:/MediaRefresh/drivers
文件夹的根目录,或作为子文件夹放入c:/MediaRefresh/drivers
。[可选] 收集配置脚本
将在 Windows 安装程序过程中或之后运行的Setupcomplete.cmd
和ErrorHandler.cmd
自定义脚本放入c:\MediaRefresh\Scripts
文件夹中。有关详细信息,请参阅将自定义脚本添加到 Windows 安装程序
更新 Windows 预安装环境 (WinPE)
Windows 预安装环境 (WinPE) 包含在 \sources
文件夹下的原始安装媒体上的 boot.wim
内。 在本部分中,我们将演练使用最新的累积服务更新对 boot.wim
进行更新的过程,并根据需要使用媒体服务环境将第三方驱动程序合并到 WinPE 环境中。
装载 WinPE boot.wim
更新 WinPE 环境的第一步是使用 PowerShell 命令 New-Item 在
c:\mediarefresh
下创建名为mounted
的临时文件夹MD c:\MediaRefresh\mounted
在更新
boot.wim
之前,我们需要确保其文件属性未设置为 ReadOnly。 使用 PowerShell 命令 Set-ItemProperty 删除 ReadOnly 属性。Set-ItemProperty -Path "c:\mediarefresh\wim\boot.wim" -Name IsReadOnly -Value $false
现在,可以使用 PowerShell 命令 Mount-WindowsImage,装载存储在索引 2 的
boot.wim
中的 WinPE 映像Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\boot.wim" -Index 2 -Path "c:\mediarefresh\Mounted"
存储在索引 2 中的
boot.wim
的 WinPE 映像的内容现在可在c:\mediarefresh\mounted
查看。
将第三方驱动程序应用到 WinPE
使用 PowerShell 命令 Add-WindowsDriver 将c:\mediarefresh\drivers
文件夹中收集的第三方驱动程序安装到c:\mediarefresh\mounted
的 WinPE。注意
若要进行测试,可以使用
-ForceUnsigned
来添加未签名的驱动程序,并替代驱动程序必须具有数字签名的要求。 有关驱动程序签名要求的详细信息,请参阅设备驱动程序和部署概述。Add-WindowsDriver -Path "c:\mediarefresh\Mounted" -Driver "c:\mediarefresh\drivers" -Recurse
将服务更新应用到 WinPE
使用 PowerShell 命令 Add-WindowsPackage 将下载到c:\mediarefresh\packages
文件夹的最新累积更新及其依赖项应用到c:\mediarefresh\mounted
的 WinPE。 此过程可能需要几分钟才能完成,但可确保 Windows 映像已应用最新的服务更新。首先应用服务堆栈更新依赖项。
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"
现在应用最新的累积更新。
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\LCU"
提示
如果遇到错误 0x800f0823,服务更新可能具有必须首先应用的依赖项。 如果已下载其依赖项,请尝试再次运行上述命令。 如果未解决此问题,可能需要下载更新的其他先决条件。
- 请记下 c:\mediarefresh\packages 中更新文件名中的 KB#######。
- 使用 KB####### 搜索 support.microsoft.com
- 打开与之匹配的第一个主题,并搜索术语“先决条件”。
- 下载提及的任何先决条件,然后再次运行上述命令。 请注意,可能需要运行命令两次,以便先应用必备组件。
- 解决错误后,请继续执行下一步。
复制已更新
Setup.exe
在继续前,使用 Robocopy 从c:\mediarefresh\mounted\sources
的 WinPE 复制更新setup.exe
到c:\mediarefresh\out\sources
。首先,我们需要使用 PowerShell 命令 Set-ItemProperty 删除
c:\mediarefresh\mounted\sources\setup.exe
上的 ReadOnly 属性。Set-ItemProperty -Path "c:\mediarefresh\out\sources\setup.exe" -Name IsReadOnly -Value $false
现在,可以使用 Robocopy 将
setup.exe
从c:\mediarefresh\mounted\sources
复制到c:\mediarefresh\out\sources
。robocopy c:\mediarefresh\mounted\sources c:\mediarefresh\out\sources setup.exe
卸载并保存对 WinPE 的更改
若要完成维护过程,请使用 PowerShell 命令 Dismount-WindowsImage 保存更改。
重要
在执行
Dismount-WindowsImage
命令之前,请确保没有任何文件资源管理器视图或命令窗口正在查看c:\mediarefresh\mounted
下的内容。 无法执行此操作将导致尝试卸载时出错。Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save
删除临时文件夹
成功卸载 boot.wim 后,现在可以使用 PowerShell 命令 Remove-Item 删除临时文件夹
c:\mediarefresh\mounted
RD c:\MediaRefresh\mounted
发布
Boot.wim
到out
文件夹现在,使用 Robocopy 将更新的
boot.wim
从c:\mediarefresh\wim
复制到c:\mediarefresh\out\sources
。robocopy c:\mediarefresh\wim c:\mediarefresh\out\sources boot.wim
存储为 boot.wim
和 setup.exe
的 Windows 预安装环境 (WinPE) 均位于 c:\mediarefresh\out\sources\
下,已完全更新。
更新 Windows IoT 企业版
Windows IoT 企业版映像包含在原始安装媒体的 \sources
文件夹下的 install.wim
中。 在准备媒体服务环境部分中,我们将 install.wim
移动到工作文件夹中。 在本部分中,我们将演练使用最新的累积服务更新对 install.wim
进行更新的过程,并在需要时使用媒体服务环境,将第三方驱动程序整合到目标设备中。 更新完成后,将 install.wim
拆分为较小的 *.swm
文件,以便将其复制到格式化为 FAT32 的 U 盘。
装载 OS install.wim
更新 WinPE 环境的第一步是使用 PowerShell 命令 New-Item 在
c:\mediarefresh
下创建名为mounted
的临时文件夹。MD c:\MediaRefresh\mounted
在更新 install.wim 之前,我们需要确保其文件属性未设置为 ReadOnly。 使用 PowerShell 命令 Set-ItemProperty 删除 ReadOnly 属性。
Set-ItemProperty -Path "c:\mediarefresh\wim\install.wim" -Name IsReadOnly -Value $false
现在,可以使用 PowerShell 命令 Mount-WindowsImage,在 install.wim 中装载存储在索引 2 的 install.wim 中的 Windows IoT 企业版映像
Mount-WindowsImage -ImagePath "c:\mediarefresh\wim\install.wim" -Index 2 -Path "c:\mediarefresh\Mounted"
install.wim 中 Windows IoT 企业版映像存储在索引 2 的内容现在可在
c:\mediarefresh\mounted
查看。
安装第三方驱动程序
使用 PowerShell 命令 Add-WindowsDriver 将c:\mediarefresh\drivers
文件夹中收集的第三方驱动程序安装到c:\mediarefresh\mounted
的 OS 映像。 该-recurse
参数支持处理子文件夹。Add-WindowsDriver -Path "c:\mediarefresh\mounted" -Driver "c:\mediarefresh\drivers" -Recurse
注意
若要进行测试,可以使用
-ForceUnsigned
来添加未签名的驱动程序,并替代驱动程序必须具有数字签名的要求。 有关驱动程序签名要求的详细信息,请参阅设备驱动程序和部署概述。添加自定义安装脚本
在将自定义安装脚本添加到 OS 映像之前,请先使用 PowerShell 命令 New-Item 在
c:\mediarefresh\mounted\windows\setup\
下创建一个scripts
文件夹。MD c:\mediarefresh\mounted\windows\setup\scripts
使用 Robocopy 将脚本从
c:\mediarefresh\scripts
复制到c:\mediarefresh\mounted\windows\setup\scripts
。robocopy c:\mediarefresh\scripts c:\mediarefresh\mounted\windows\setup\scripts *.cmd
将服务包应用到 OS 映像
使用 PowerShell 命令 Add-WindowsPackage 将下载到c:\mediarefresh\packages
文件夹的最新累积更新及其依赖项应用到c:\mediarefresh\mounted
的 WinPE。首先应用服务堆栈更新依赖项。
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\SSU"
现在应用最新的累积更新。
Add-WindowsPackage -Path "c:\mediarefresh\mounted" -PackagePath "c:\mediarefresh\packages\LCU"
提示
如果遇到错误 0x800f0823,服务更新可能具有必须首先应用的依赖项。 如果已下载其依赖项,请尝试再次运行上述命令。 如果未解决此问题,可能需要下载更新的其他先决条件。
- 请记下 c:\mediarefresh\packages 中更新文件名中的 KB#######。
- 使用 KB####### 搜索 support.microsoft.com
- 打开与之匹配的第一个主题,并搜索术语“先决条件”。
- 下载提及的任何先决条件,然后再次运行上述命令。 请注意,可能需要运行命令两次,以便先应用必备组件。
- 解决错误后,请继续执行下一步。
保存并卸载更新的 install.wim
若要完成维护过程,请使用 PowerShell 命令 Dismount-WindowsImage 保存更改。重要
在执行
Dismount-WindowsImage
命令之前,请确保没有任何文件资源管理器视图或命令窗口正在查看c:\mediarefresh\mounted
下的内容。 无法执行此操作将导致尝试卸载时出错。Dismount-WindowsImage -path "c:\mediarefresh\mounted" -save
删除临时文件夹
mounted
成功卸载 boot.wim 后,现在可以使用 PowerShell 命令 Remove-Item 删除临时文件夹c:\mediarefresh\mounted
RD c:\mediarefresh\mounted
拆分 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
OS 安装映像最初存储为 install.wim
,现在以 install.swm
和 install2.swm
的形式存储在 c:\mediarefresh\out\sources\
下,设置使用它们就像使用原始 install.wim
一样。
将更新的媒体复制到 U 盘
如果尚未创建可启动的 U 盘,请先执行以下步骤从 U 盘安装 Windows。
创建更新的安装介质的最后一步是使用 Robocopy 将 c:\mediarefresh\out
的内容复制到可启动的 U 盘。
robocopy c:\mediarefresh\out <DriveLetter>:\ /e
其中 <DriveLetter>
为与 U 盘关联的驱动器号
将 Windows 安装到新设备
将 U 盘连接到目标设备。
打开该设备,然后按可打开计算机启动设备选择菜单的键,例如 Esc/F10/F12 等键。 选择从 U 盘启动设备的选项。
Windows 安装程序启动。 按照说明来安装 Windows
提示
可能需要咨询设备制造商的说明,以将其配置为从 U 盘启动,此过程在设备上不起作用。
安装的初始阶段完成,并且设备重新启动后,安装程序可能会从头再次启动。 如果安装程序再次启动,请取消安装程序并关闭计算机,然后移除 U 盘并打开设备以继续执行安装程序的下一阶段。
完整脚本
本部分包含一个完整的脚本,该脚本会自动连续执行每个媒体服务步骤。 使用此脚本之前,必须完成本文的“准备媒体服务环境”部分。 准备就绪后,将以下 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