Advertisement
CahitYilmaz

Windows 10 Customization PowerShell Script

Apr 14th, 2017
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ********************************** DEFINE VARIABLES ********************************
  2. $env:WorkDir = "D:\TEST"
  3. $installwim = "$env:WorkDir\Dvd\sources\install.wim"
  4. $slwim = "$env:WorkDir\Wim\sl.wim"
  5. $bootwim = "$env:WorkDir\Dvd\sources\boot.wim"
  6. $winrePro = "$env:WorkDir\Mount\pro\windows\system32\recovery\winre.wim"
  7. $winreHome = "$env:WorkDir\Mount\home\windows\system32\recovery\winre.wim"
  8. $winreSL = "$env:WorkDir\Mount\sl\windows\system32\recovery\winre.wim"
  9. $mntPro = "$env:WorkDir\Mount\pro"
  10. $mntHome = "$env:WorkDir\Mount\home"
  11. $mntSL = "$env:WorkDir\Mount\sl"
  12. $mntBoot = "$env:WorkDir\Mount\boot"
  13. $mntWinrePro = "$env:WorkDir\Mount\winrePro"
  14. $mntWinreHome = "$env:WorkDir\Mount\winreHome"
  15. $mntWinreSL = "$env:WorkDir\Mount\winreSL"
  16. $Updates = "$env:WorkDir\Updates"
  17. $Reg = "$env:WorkDir\Reg"
  18. $Temp = "$env:WorkDir\Temp"
  19. $LangEN = "$env:WorkDir\LangPack\en-us"
  20. $LangWinreEN = "$env:WorkDir\LangPack\winre\en-us"
  21. $LangBootEN = "$env:WorkDir\LangPack\boot\en-us"
  22. $winsxsPro = "$mntPro\Windows\WinSxs"
  23. $winsxsHome = "$mntHome\Windows\WinSxs"
  24. $winsxsSL= "$mntSL\Windows\WinSxs"
  25. $imagex = "$env:WorkDir\Tools\imagex_x64.exe"
  26. $SetACL = "$env:WorkDir\Tools\SetACL_x64.exe"
  27. $CastToDeviceREG = "HKLM:\WIM_Software\Classes\CLSID\{7AD84985-87B4-4a16-BE58-8B72A5B390F7}"
  28.  
  29. $apps = @(
  30. "Microsoft.3DBuilder"
  31. "Microsoft.BingWeather"
  32. "Microsoft.DesktopAppInstaller"
  33. "Microsoft.Getstarted"
  34. "Microsoft.Messaging"
  35. "Microsoft.Microsoft3DViewer"
  36. "Microsoft.MicrosoftOfficeHub"
  37. "Microsoft.MicrosoftSolitaireCollection"
  38. #"Microsoft.MicrosoftStickyNotes"
  39. "Microsoft.MSPaint"
  40. "Microsoft.Office.OneNote"
  41. "Microsoft.OneConnect"
  42. "Microsoft.People"
  43. "Microsoft.SkypeApp"
  44. "Microsoft.StorePurchaseApp"
  45. "Microsoft.Wallet"
  46. #"Microsoft.Windows.Photos"
  47. "Microsoft.WindowsAlarms"
  48. "Microsoft.WindowsCalculator"
  49. #"Microsoft.WindowsCamera"
  50. "microsoft.windowscommunicationsapps"
  51. "Microsoft.WindowsFeedbackHub"
  52. "Microsoft.WindowsMaps"
  53. "Microsoft.WindowsSoundRecorder"
  54. #"Microsoft.WindowsStore"
  55. "Microsoft.XboxApp"
  56. "Microsoft.XboxGameOverlay"
  57. "Microsoft.XboxIdentityProvider"
  58. "Microsoft.XboxSpeechToTextOverlay"
  59. "Microsoft.ZuneMusic"
  60. "Microsoft.ZuneVideo"
  61. )
  62. $packages = @(
  63. "Microsoft-Windows-QuickAssist-Package~31bf3856ad364e35~amd64~~10.0.15063.0"
  64. "Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~~10.0.15063.0"
  65. #"Microsoft-Windows-MediaPlayer-Package~31bf3856ad364e35~amd64~~10.0.15063.0"
  66. )
  67. $featuresEnabling = @(
  68. #"DirectPlay"
  69. "NetFx3"
  70. )
  71. $featuresDisabling = @(
  72. "Microsoft-Windows-HyperV-Guest-Package"
  73. #"WindowsMediaPlayer"
  74. "FaxServicesClientPackage"
  75. )
  76. $mntWimPaths = @("$mntPro","$mntHome","$mntSL ")
  77. $mntWinRePaths = @("$mntWinrePro","$mntWinreHome","$mntWinreSL")
  78. $winsxsPaths = @("$winsxsPro","$winsxsHome","$winsxsSL")
  79.  
  80. # ********************************** MENU ********************************
  81. Write-Host
  82. Write-Host "Press ENTER key to continue..."
  83. Read-Host
  84. CLS
  85.  
  86. # ********************************** MOUNT IMAGES ********************************
  87. $host.ui.RawUI.WindowTitle = "Mounting install.wim Image"
  88. Mount-WindowsImage -ImagePath "$installwim" -Index 1 -Path "$mntPro"
  89. Mount-WindowsImage -ImagePath "$installwim" -Index 2 -Path "$mntHome"
  90. Mount-WindowsImage -ImagePath "$slwim" -Index 1 -Path "$mntSL"
  91. CLS
  92.  
  93. $host.ui.RawUI.WindowTitle = "Mounting winre.wim Image"
  94. Mount-WindowsImage -ImagePath "$winrePro" -Index 1 -Path "$mntWinrePro"
  95. Mount-WindowsImage -ImagePath "$winreHome" -Index 1 -Path "$mntWinreHome"
  96. Mount-WindowsImage -ImagePath "$winreSL" -Index 1 -Path "$mntWinreSL"
  97. CLS
  98.  
  99. $host.ui.RawUI.WindowTitle = "Mounting boot.wim Image"
  100. Mount-WindowsImage -ImagePath "$bootwim" -Index 2 -Path "$mntBoot"
  101. CLS
  102.  
  103. # ********************************** REMOVE APPS AND PACKAGE ********************************
  104. $host.ui.RawUI.WindowTitle = "Removing Apps and Packages"
  105. Foreach ($mntPath in $mntWimPaths) {
  106.     Foreach ($app in $apps) {
  107.         Get-AppxProvisionedPackage -Path $mntPath | Where DisplayName -EQ $app | Remove-AppxProvisionedPackage
  108.         Write-Host "Removed App : " $app " From " $mntPath -foregroundcolor "white" -backgroundcolor "red"
  109.         Write-Host ""
  110.     }
  111. }
  112.  
  113. Foreach ($mntPath in $mntWimPaths) {
  114.      Foreach ($package in $packages) {
  115.         Get-WindowsPackage -Path $mntPath | Where PackageName -EQ $package | Remove-WindowsPackage
  116.         Write-Host "Removed Package : " $package " From " $mntPath -foregroundcolor "white" -backgroundcolor "red"
  117.     }
  118. }
  119.  
  120. # ********************************** ENABLE - DISABLE FEATURES ********************************
  121. $host.ui.RawUI.WindowTitle = "Enable - Disable Features"
  122. Foreach ($mntPath in $mntWimPaths) {
  123.     Foreach ($feature in $featuresEnabling) {
  124.         Get-WindowsOptionalFeature -Path $mntPath | Where FeatureName -EQ $feature | Enable-WindowsOptionalFeature
  125.     }
  126. }
  127.  
  128. Foreach ($mntPath in $mntWimPaths) {
  129.     Foreach ($feature in $featuresDisabling) {
  130.         Get-WindowsOptionalFeature -Path $mntPath | Where FeatureName -EQ $feature | Disable-WindowsOptionalFeature
  131.     }
  132. }
  133.  
  134. # ********************************** INTEGRATE LANGUAGE PACK ********************************
  135. $host.ui.RawUI.WindowTitle = "Integrating Windows Language Pack"
  136. Foreach ($mntPath in $mntWimPaths) {
  137.         Add-WindowsPackage -Path $mntPath -PackagePath $LangEN
  138. }
  139. DISM /Image:"$mntPro" /Gen-LangINI /Distribution:"$env:WorkDir\Dvd"
  140. CLS
  141.  
  142. $host.ui.RawUI.WindowTitle = "Integrating Setup Language Pack"
  143. Add-WindowsPackage -Path "$mntBoot" -PackagePath "$LangBootEN"
  144. Copy-Item "$env:WorkDir\Dvd\sources\lang.ini" -Destination "$mntBoot\sources\lang.ini" -Force
  145. CLS
  146.  
  147. $host.ui.RawUI.WindowTitle = "Integrating WinRe Language Pack"
  148. Foreach ($mntPath in $mntWinRePaths) {
  149.     Add-WindowsPackage -Path $mntPath -PackagePath $LangWinreEN
  150.     CLS
  151. }
  152.  
  153. # ********************************** INTEGRATE UPDATES ********************************
  154. $host.ui.RawUI.WindowTitle = "Integrating Windows Updates"
  155. Foreach ($mntPath in $mntWimPaths) {
  156.     Add-WindowsPackage -Path $mntPath -PackagePath "$Updates"
  157.     CLS
  158. }
  159.  
  160. # ********************************** IMPORT REGISTRY ********************************
  161. $host.ui.RawUI.WindowTitle = "Importing Registry Settings"
  162. Foreach ($mntPath in $mntWimPaths) {
  163.     REG Load HKLM\WIM_Default $mntPath\Users\Default\NTUSER.DAT
  164.     REG Load HKLM\WIM_Software $mntPath\Windows\System32\config\SOFTWARE
  165.     REG Load HKLM\WIM_System $mntPath\Windows\System32\config\SYSTEM
  166.     $SetACL -on $CastToDeviceREG -ot reg -actn setowner -ownr "n:Administrators" -rec yes
  167.     $SetACL -on $CastToDeviceREG -ot reg -actn ace -ace "n:Administrators;p:full" -rec yes
  168.     REG Import $Reg\System.reg
  169.     REG Import $Reg\IE.reg
  170.     REG Import $Reg\NavigationPane.reg
  171.     REG Import $Reg\Photo.reg
  172.     REG Import $Reg\Privacy.reg
  173.     REG Import $Reg\ViewSetting.reg
  174.     REG Import $Reg\Context.reg
  175.     REG Unload HKLM\WIM_Default
  176.     REG Unload HKLM\WIM_Software
  177.     REG Unload HKLM\WIM_System
  178. }
  179.  
  180. # ********************************** DISMOUNT IMAGES ********************************
  181. $host.ui.RawUI.WindowTitle = "DisMounting WinRe Image"
  182. Foreach ($mntPath in $mntWinRePaths) {
  183.     Dismount-WindowsImage -Path $mntPath -Save
  184. }
  185. Export-WindowsImage -SIP "$winrePro" -SI 1 -DIP "$Temp\winre.wim" -DN "Microsoft Windows Recovery Environment (x64)" -CompressionType max
  186. Move-Item -Path "$Temp\winre.wim" -Destination "$mntPro\windows\system32\recovery" -Force
  187. Export-WindowsImage -SIP "$winreHome" -SI 1 -DIP "$Temp\winre.wim" -DN "Microsoft Windows Recovery Environment (x64)" -CompressionType max
  188. Move-Item -Path "$Temp\winre.wim" -Destination "$mntHome\windows\system32\recovery" -Force
  189. Export-WindowsImage -SIP "$winreSL" -SI 1 -DIP "$Temp\winre.wim" -DN "Microsoft Windows Recovery Environment (x64)" -CompressionType max
  190. Move-Item -Path "$Temp\winre.wim" -Destination "$mntSL\windows\system32\recovery" -Force
  191. CLS
  192.  
  193. $host.ui.RawUI.WindowTitle = "DisMounting install.wim"
  194. Foreach ($mntPath in $mntWimPaths) {
  195.     Dismount-WindowsImage -Path $mntPath -Save
  196.     Write-Host "Dismounted Image : " $mntPath -foregroundcolor "white" -backgroundcolor "red"
  197.     Write-Host ""
  198. }
  199.  
  200. $host.ui.RawUI.WindowTitle = "DisMounting boot.wim"
  201. Dismount-WindowsImage -Path "$mntBoot" -Save
  202. CLS
  203.  
  204. # ********************************** EXPORT IMAGES ********************************
  205. $host.ui.RawUI.WindowTitle = "Exporting Images"
  206. Export-WindowsImage -SIP "$installwim" -SI 1 -DIP "$Temp\install.wim" -DN "Windows 10 Pro" -CompressionType max
  207. Export-WindowsImage -SIP "$installwim" -SI 2 -DIP "$Temp\install.wim" -DN "Windows 10 Home" -CompressionType max
  208. Export-WindowsImage -SIP "$slwim" -SI 1 -DIP "$Temp\install.wim" -DN "Windows 10 Home Single Language" -CompressionType max
  209. Export-WindowsImage -SIP "$bootwim" -SI 1 -DIP "$Temp\boot.wim" -DN "Microsoft Windows PE (x64)" -CompressionType max
  210. Export-WindowsImage -SIP "$bootwim" -SI 2 -DIP "$Temp\boot.wim" -DN "Microsoft Windows Setup (x64)" -CompressionType max
  211. Move-Item -Path "$Temp\*" -Destination "$env:WorkDir\Dvd\sources" -Force
  212.  
  213. # ********************************** MAKE ISO ********************************
  214. Start-Process cmd.exe "/c $env:WorkDir\makeiso.bat"
  215. EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement