Public/ADK/Edit-ADKwinpe.wim.ps1
<#
.SYNOPSIS Adds PowerShell and PowerShell Gallery support to ADK's x64 winpe.wim .Description Adds PowerShell and PowerShell Gallery support to ADK's x64 winpe.wim. This will speed things up with MDT and MEM CM going forward .LINK https://osd.osdeploy.com/module/functions/adk .NOTES 21.3.15.2 Initial Release #> function Edit-ADKwinpe.wim { [CmdletBinding()] param () #======================================================================= # Start the Clock #======================================================================= $StartTime = Get-Date #======================================================================= # Require WinOS #======================================================================= if ((Get-OSDGather -Property IsWinPE)) { Write-Warning "$($MyInvocation.MyCommand) cannot be run from WinPE" Break } #======================================================================= # Require Admin Rights #======================================================================= if ((Get-OSDGather -Property IsAdmin) -eq $false) { Write-Warning "$($MyInvocation.MyCommand) requires Admin Rights ELEVATED" Break } #======================================================================= # Require cURL #======================================================================= if (-NOT (Test-Path "$env:SystemRoot\System32\curl.exe")) { Write-Warning "$($MyInvocation.MyCommand) could not find $env:SystemRoot\System32\curl.exe" Write-Warning "Get a newer Windows version!" Break } #======================================================================= # Set VerbosePreference #======================================================================= $CurrentVerbosePreference = $VerbosePreference $VerbosePreference = 'Continue' #======================================================================= # Get ADK #======================================================================= $WinPEArch = 'amd64' $AdkPaths = Get-AdkPaths -Arch $WinPEArch if ($null -eq $AdkPaths) { Write-Warning "Could not get ADK going, sorry" Break } #======================================================================= # Get WinPE.wim #======================================================================= $WimSourcePath = $AdkPaths.WimSourcePath if (-NOT (Test-Path $WimSourcePath)) { Write-Warning "Could not find $WimSourcePath, sorry" Break } $WimSourceItem = Get-Item $WimSourcePath #======================================================================= # Create Backup #======================================================================= if (-NOT (Test-Path "$($WimSourceItem.Directory)\winpe.bak")) { $WimSourceItem | Copy-Item -Destination "$($WimSourceItem.Directory)\winpe.bak" -Force -ErrorAction Stop } #======================================================================= # Mount-MyWindowsImage #======================================================================= $MountMyWindowsImage = Mount-MyWindowsImage $WimSourceItem $MountPath = $MountMyWindowsImage.Path #======================================================================= # Add Packages #======================================================================= $ErrorActionPreference = 'Ignore' $WinPEOCs = $AdkPaths.WinPEOCs Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-WMI.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-WMI_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-HTA.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-HTA_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-NetFx.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-NetFx_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-Scripting.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-Scripting_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PowerShell.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-PowerShell_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-SecureStartup.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-SecureStartup_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-DismCmdlets.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-DismCmdlets_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-Dot3Svc.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-Dot3Svc_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-EnhancedStorage.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-EnhancedStorage_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-FMAPI.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-GamingPeripherals.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PPPoE.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-PPPoE_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PlatformId.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PmemCmdlets.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-PmemCmdlets_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-RNDIS.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-RNDIS_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-SecureBootCmdlets.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-StorageWMI.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-StorageWMI_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-WDS-Tools.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-WDS-Tools_en-us.cab" #======================================================================= # cURL #======================================================================= Write-Verbose "Adding curl.exe to $MountPath" if (Test-Path "$env:SystemRoot\System32\curl.exe") { robocopy "$env:SystemRoot\System32" "$MountPath\Windows\System32" curl.exe /ndl /nfl /njh /njs /b } else { Write-Warning "Could not find $env:SystemRoot\System32\curl.exe" Write-Warning "You must be using an old version of Windows" } #======================================================================= # PowerShell Execution Policy #======================================================================= Write-Verbose "Setting PowerShell ExecutionPolicy to Bypass in $MountPath" Set-WindowsImageExecutionPolicy -Path $MountPath -ExecutionPolicy Bypass #======================================================================= # Enable PowerShell Gallery #======================================================================= Write-Verbose "Enabling PowerShell Gallery support in $MountPath" Enable-PEWindowsImagePSGallery -Path $MountPath #Write-Verbose "Saving OSD to $MountPath\Program Files\WindowsPowerShell\Modules" #Save-Module -Name OSD -Path "$MountPath\Program Files\WindowsPowerShell\Modules" -Force #======================================================================= # Startnet #======================================================================= #Write-Verbose "Adding PowerShell.exe to Startnet.cmd" #Add-Content -Path "$MountPath\Windows\System32\Startnet.cmd" -Value 'start powershell.exe' -Force #======================================================================= # DriverPath #======================================================================= <# foreach ($Driver in $DriverPath) { Add-WindowsDriver -Path "$($MountMyWindowsImage.Path)" -Driver "$Driver" -Recurse -ForceUnsigned } #> #======================================================================= # Save WIM #======================================================================= $MountMyWindowsImage | Dismount-MyWindowsImage -Save #======================================================================= # Restore VerbosePreference #======================================================================= $VerbosePreference = $CurrentVerbosePreference #======================================================================= # Complete #======================================================================= $EndTime = Get-Date $TimeSpan = New-TimeSpan -Start $StartTime -End $EndTime Write-Host -ForegroundColor DarkGray "=========================================================================" Write-Host -ForegroundColor Yellow "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) $($MyInvocation.MyCommand.Name) " -NoNewline Write-Host -ForegroundColor Cyan "Completed in $($TimeSpan.ToString("mm' minutes 'ss' seconds'"))" #======================================================================= } |