chuston

Windows 10 22H2 Automox Code

Feb 21st, 2023
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 3.72 KB | Software | 0 0
  1. #Evaluation Code Start
  2.  
  3.  
  4. #Evalaution Script - Determine if Target Release Version Registry keys exist and are set
  5.  
  6.  
  7.  
  8.  
  9.  
  10. # Define Values in this section and ensure they match the values set in the remediation script
  11.  
  12. #############################################
  13.  
  14. $rValue = '1' #Enable Target Release Version 0 = Disabled, 1 = Enabled
  15.  
  16. $rProductValue = 'Windows 10'
  17.  
  18. $rInfoValue = '22H2' #Specify Windows 10 Target Release Version.  Select the preferred version from https://docs.microsoft.com/en-us/windows/release-information/
  19.  
  20. #############################################
  21.  
  22.  
  23.  
  24. #Predefined variables
  25.  
  26. $rPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate'
  27.  
  28. $rProductName = 'ProductVersion'
  29.  
  30. $rVersion = 'TargetReleaseVersion'
  31.  
  32. $rVersionInfo = 'TargetReleaseVersionInfo'
  33.  
  34.  
  35.  
  36. #Check if $rVersion registry value missing
  37.  
  38.  
  39.  
  40. try{
  41.  
  42.     $cVersion = Get-ItemPropertyValue -Path $rPath -Name $rVersion -ErrorAction Stop
  43.    
  44.     $cProductInfo = Get-ItemPropertyValue -Path $rPath -Name $rProductName -ErrorAction Stop
  45.  
  46.     $cVersionInfo = Get-ItemPropertyValue -Path $rPath -Name $rVersionInfo -ErrorAction Stop
  47.  
  48. }
  49.  
  50. catch{
  51.  
  52.     Write-Error "Unable to read registry values"
  53.  
  54.     Exit -1
  55.  
  56. }
  57.  
  58.  
  59.  
  60. #Check if registry value data matches defined values
  61.  
  62. if (($cVersion -eq $rValue) -and ($rInfoValue -eq $cVersionInfo) -and ($cProductInfo -eq $rProductValue)) {
  63.  
  64.    Exit 0
  65.  
  66. } else { Exit -1 }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. #Remediation Code Start
  87.  
  88.  
  89.  
  90. <#
  91.  
  92. .SYNOPSIS
  93.  
  94. Configure Windows 10 Target Release Version
  95.  
  96.  
  97.  
  98. .DESCRIPTION
  99.  
  100.   Uses group policy registry keys to Enable and configure Target Release Version for Windows 10.  
  101.  
  102.  
  103.  
  104. Target Release Version
  105.  
  106. Enable = 1 or Disable = 0
  107.  
  108.  
  109.  
  110. Target Releaese Version Info
  111.  
  112. Specify the preferred version of Windows 10.  Enter version from https://docs.microsoft.com/en-us/windows/release-information/
  113.  
  114.  
  115.  
  116. .NOTES
  117.  
  118. Author: Automox
  119.  
  120. Please note, these settings remain in the registry, and would require modification or removal to change or revert back to default.
  121.  
  122.  
  123.  
  124. .PREREQUISITES
  125.  
  126.   Windows 10 1803 or higher
  127.  
  128.   Managable SKU (Pro, Education, Enterprise, Business)
  129.  
  130. #>
  131.  
  132.  
  133.  
  134. # Define Values in this section
  135.  
  136. #############################################
  137.  
  138. $rValue = '1' #Enable Target Release Version 0 = Disabled, 1 = Enabled
  139.  
  140. $rInfoValue = '22H2' #Specify Windows 10 Target Release Version.  Select the preferred version from https://docs.microsoft.com/en-us/windows/release-information/
  141.  
  142. $rInfoProduct = 'Windows 10'
  143.  
  144. #############################################
  145.  
  146. $rPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate'
  147.  
  148. $rKeyPath = 'HKLM:\Software\Policies\Microsoft\Windows'
  149.  
  150. $rVersion = 'TargetReleaseVersion'
  151.  
  152. $rVersionInfo = 'TargetReleaseVersionInfo'
  153.  
  154. $rInfoProductName = 'ProductVersion'
  155.  
  156. try {
  157.  
  158.   if(-not(Test-Path -path $rPath)){
  159.  
  160.     New-Item -Path $rPath -Force -ErrorAction Stop | Out-Null
  161.  
  162.   }
  163.  
  164.     Write-Output "SUCESS: Added Windows Product"
  165.    
  166.     New-ItemProperty -Path $rPath -Name $rInfoProductName -PropertyType String -Value $rInfoProduct -Force -ErrorAction Stop | Out-Null
  167.    
  168.     Write-Output "SUCCESS: Target Release Version keys set`t"
  169.  
  170.     New-ItemProperty -Path $rPath -Name $rVersion -PropertyType DWord -Value $rValue -Force -ErrorAction Stop | Out-Null
  171.  
  172.     Write-Output "$rpath exists`t"
  173.  
  174.     New-ItemProperty -Path $rPath -Name $rVersionInfo -PropertyType String -Value $rInfoValue -Force -ErrorAction Stop | Out-Null
  175.  
  176.     Write-Output "$rVersion = $rvalue and $rVersionInfo = $rInfoValue`t"    
  177.  
  178.  
  179.  
  180.     Exit 0
  181.  
  182. } catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber
  183.  
  184.     Write-Error $Exception
  185.  
  186.     Exit 90
  187.  
  188. }
Tags: Automox
Advertisement
Add Comment
Please, Sign In to add comment