Guest User

8.1/10 Update Slipstreamer

a guest
Jul 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Load-Module DISM
  2. $wsusoffline_directory = "PATH_TO_WSUSOFFLINE_BASE_DIRECTORY"
  3. $work_base_directory = "PATH_TO_WORK_DIRECTORY"
  4. $scratch_directory = "$($wsusoffline_directory)\temp"
  5. $scratch_image = "$($scratch_directory)\work.wim"
  6. $image_index = 1 # or whatever it is on your WIM file
  7. $cabs = Get-ChildItem -Path "$($wsusoffline_directory)\client" -Recurse -Include *.cab,*.msu -Exclude wsusscn2.cab | Sort-Object LastWriteTime
  8. Write-Host "Mounting Image"
  9. $mounted_image = Mount-WindowsImage -ImagePath $scratch_image -Index $image_index -Path "$($work_base_directory)\mountpoint"
  10. Write-Host "Adding Packages to Image"
  11. $failed_updates = [ordered]@{}
  12. foreach ($cab in $cabs){
  13.     $add_result = Add-WindowsPackage -PackagePath $cab.FullName -Path "$($work_base_directory)\mountpoint" -Verbose -LogPath "$($work_base_directory)\updates.log" -LogLevel WarningsInfo -ScratchDirectory $scratch_directory
  14.     if($? -eq $true){
  15.         ($scratch_image,$cab.FullName) -join " :: " | Out-File -FilePath "$($work_base_directory)\updates-success.log" -Append
  16.     } else {
  17.         if($Error[0].Exception.HResult -eq 0x800f081e){
  18.             ($scratch_image,$cab.FullName) -join " :: " | Out-File -FilePath "$($work_base_directory)\updates-Notapplicable.log" -Append
  19.         } else {
  20.             ($scratch_image,$cab.FullName) -join " :: " | Out-File -FilePath "$($work_base_directory)\updates-failed.log" -Append
  21.             $failed_updates.Add($cab, 1)
  22.         }
  23.     }
  24. }
  25. while ($failed_updates.Count -gt 0) {
  26.     foreach ($cab in $failed_updates.Keys){
  27.         $add_result = Add-WindowsPackage -PackagePath $cab.FullName -Path "$($work_base_directory)\mountpoint" -Verbose -LogPath "$($work_base_directory)\updates.log" -LogLevel WarningsInfo -ScratchDirectory $scratch_directory
  28.         if($? -eq $true){
  29.             ($scratch_image,$cab.FullName) -join " :: " | Out-File -FilePath "$($work_base_directory)\updates-success.log" -Append
  30.             $failed_updates.Remove($cab)
  31.         } else {
  32.             $failed_updates[$cab] += 1
  33.             ($scratch_image,$cab.FullName, "Try #$($failed_updates[$cab])]") -join " :: " | Out-File -FilePath "$($work_base_directory)\updates-failed.log" -Append
  34.             if ($failed_updates[$cab] -ge 5){
  35.                 $failed_updates.Remove($cab)
  36.             }
  37.         }
  38.     }
  39. }
  40. Write-Host "Enabling Features"
  41. $features = Get-WindowsOptionalFeature -Path "$($work_base_directory)\mountpoint" -LogPath "$($work_base_directory)\features.log" -ScratchDirectory $scratch_directory -LogLevel WarningsInfo -Verbose
  42. $enable_features = $features | Where-Object {
  43.     $_.FeatureName -in (
  44.         "MicrosoftWindowsPowerShellV2Root", "MicrosoftWindowsPowerShellV2", "NetFx3",
  45.         "NetFx4-AdvSrvs", "TelnetClient", "TFTP"
  46.     ) -and $_.State -notin ([Microsoft.Dism.Commands.FeatureState]::Enabled,
  47.                             [Microsoft.Dism.Commands.FeatureState]::EnablePending,
  48.                             [Microsoft.Dism.Commands.FeatureState]::Superseded)
  49. } | Enable-WindowsOptionalFeature -Path "$($work_base_directory)\mountpoint" -LogPath "$($work_base_directory)\features.log" -ScratchDirectory $scratch_directory -LogLevel WarningsInfo -Verbose
  50. Write-Host "Disabling Features"
  51. $disable_features = $features | Where-Object {
  52.     $_.FeatureName -in (
  53.         "WCF-Services45", "WCF-TCP-PortSharing45", "NetFx4Extended-ASPNET45",
  54.         "Microsoft-Hyper-V-All", "SimpleTCP", "SNMP",
  55.         "IIS-WebServerRole", "IIS-WebServer", "IIS-FTPServer",
  56.         "IIS-FTPSvc", "IIS-FTPExtensibility", "Microsoft-Windows-MobilePC-Client-Premium-Package-net",
  57.         "Microsoft-Windows-MobilePC-LocationProvider-INF", "TelnetServer", "SMB1Protocol"
  58.     ) -and $_.State -notin ([Microsoft.Dism.Commands.FeatureState]::Disabled,
  59.                             [Microsoft.Dism.Commands.FeatureState]::DisablePending,
  60.                             [Microsoft.Dism.Commands.FeatureState]::DisabledWithPayloadRemoved,
  61.                             [Microsoft.Dism.Commands.FeatureState]::Superseded)
  62. } | Disable-WindowsOptionalFeature -Path "$($work_base_directory)\mountpoint" -LogPath "$($work_base_directory)\features.log" -ScratchDirectory $scratch_directory -LogLevel WarningsInfo -Verbose
  63. Write-Host "Disabling Bloatware"
  64. $disable_bloatware = Get-AppxProvisionedPackage -Path "$($work_base_directory)\mountpoint" -LogPath $($work_base_directory)\appx.log" -ScratchDirectory $scratch_directory -LogLevel WarningsInfo -Verbose | Where-Object {
  65.    $_.DisplayName -in (
  66.        "Microsoft.BingFinance", "Microsoft.BingFoodAndDrink", "Microsoft.BingHealthAndFitness",
  67.        "Microsoft.BingMaps", "Microsoft.BingNews", "Microsoft.BingSports",
  68.        "Microsoft.BingTravel", "Microsoft.BingWeather", "Microsoft.SkypeApp",
  69.        "Microsoft.XboxLIVEGames", "Microsoft.ZuneMusic", "Microsoft.ZuneVideo"
  70.    )
  71. } | Remove-AppxProvisionedPackage -path "$($work_base_directory)\mountpoint" -LogPath "$($work_base_directory)\appx.log" -ScratchDirectory $scratch_directory -LogLevel WarningsInfo -Verbose
  72. Write-Host "Injecting Post-Setup executables"
  73. # Copy desired executables (frameworks, runtimes, etc) to (IMAGE)\postsetup and append entries to (image)\Windows\Setup\Scripts\SetupComplete.cmd to run unattended installation
  74. $postsetup_script_file = "$($work_base_directory)\mountpoint\Windows\Setup\Scripts\SetupComplete.cmd"
  75. [System.Collections.ArrayList]$postsetup_script = Get-Content $postsetup_script_file
  76. ##Ensure cleanup is done on post-install
  77. Write-Host "Adding Component Store Cleanup"
  78. $component_store_cleanup = (
  79.    "start /wait c:\windows\system32\dism.exe /Online /LogPath:c:\setup.log\cleanup-spsuperseded.log /LogLevel:3 /Cleanup-Image /SPSuperseded",
  80.    "start /wait c:\windows\system32\dism.exe /Online /LogPath:c:\setup.log\cleanup-resetbase.log /LogLevel:3 /Cleanup-Image /StartComponentCleanup /ResetBase",
  81.    "start /wait c:\windows\system32\dism.exe /Online /LogPath:c:\setup.log\cleanup-components.log /LogLevel:3 /Cleanup-Image /StartComponentCleanup"
  82. )
  83. [System.Collections.ArrayList]$postsetup_script = $postsetup_script | Where-Object { $_ -notin $component_store_cleanup }
  84. $component_store_cleanup | ForEach-Object { $postsetup_script.Insert($postsetup_script.IndexOf("md c:\setup.log")+1, $_ ) }
  85. Write-Host "Writing New PostSetup Script"
  86. $postsetup_script | Out-File $postsetup_script_file -Encoding ascii -Verbose
  87. Write-Host "Committing Changes to Image"
  88. $retry_counter = 10
  89. do{
  90.    $retry_counter -= 1
  91.    Dismount-WindowsImage -Path "$($work_base_directory)\mountpoint" -Save
  92. }while($? -eq $false -and $retry_counter -gt 0)
Add Comment
Please, Sign In to add comment