Management

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 778 other subscribers

Social

  • LinkedIn
  • RSS Feed for Posts
  • Twitter
  • StumbleUpon

[Solved] Windows 10 : Disable Windows 10 autoupgrade

This script disables the automatic upgrade to Windows 10, by placing 2 regkeys if not set already.

<#
.SYNOPSIS
Disable Windows 10 Upgrade V10

.DESCRIPTION
This script disables the upgrade to Windows 10 by placing 2 regkeys to this computer.

.INPUTS
Disable-Windows-10-Upgrade-V10.ps1Create-log.ps1

.OUTPUTS
This script, creates some regkeys for disabling the upgrade to Windows 10

.Prerequisites
Nothing

.EXAMPLE
Start this script
.\Disable-Windows-10-Upgrade-V10.ps1

.EXAMPLE
Start this script for Verbose option
.\Disable-Windows-10-Upgrade-V10.ps1 -Verbose

.LINK
http://www.vspbreda.nl

.NOTES
Written By: Richard Voogt
Website:	http://www.vspbreda.nl
Twitter:	http://twitter.com/rvoogt

Change Log
V1.0, 24-12-2015 - first release

#>

[CmdletBinding()]
param ()

function Test-RegistryValue {

	param (

			[parameter(Mandatory=$true)]
			[ValidateNotNullOrEmpty()]$Path,

			[parameter(Mandatory=$true)]	
			[ValidateNotNullOrEmpty()]$Value
			)
    try
		{
        $exists = Get-ItemProperty $Path $Value -ErrorAction stop
        Write-Output "Test-RegistryValue: $exists"
        if (($exists -eq $null) -or ($exists.Length -eq 0))
			{
            return $false
			}
        else
			{
            return $true
			}
		}
    catch
		{
        return $false
		}
	}


function Test-ChangeRegKey {

	param (

		[parameter(Mandatory=$true)]
		[ValidateNotNullOrEmpty()]$RegKey1,

		[parameter(Mandatory=$true)]
		[ValidateNotNullOrEmpty()]$RegSubKey1,

		[parameter(Mandatory=$true)]
		[ValidateNotNullOrEmpty()]$RegSubKeyWord1,

		[parameter(Mandatory=$true)]
		[ValidateNotNullOrEmpty()]$RegSubKeyWord1Value
		)
	
	$RegKeyTotal1 = "$RegKey1\$RegSubKey1"
	Write-Verbose "RegKey1 = $RegKey1"
	Write-Verbose "RegSubKey1 = $RegSubKey1"
	Write-Verbose "RegSubKeyWord1 = $RegSubKeyWord1"
	Write-Verbose "RegSubKeyWord1Value = $RegSubKeyWord1Value"
    Write-Verbose "RegKeyTotal1 = $RegKeyTotal1"

	$TestPathRegKey1 = Test-Path "HKLM:\$RegKey1"
	Write-Verbose "TestPathRegKey1 = $TestPathRegKey1"
	If ($TestPathRegKey1 -eq $False)
		{
		Write-Output "Regkey $RegKey1 Doesn't exist, it is being created"
		Write-Verbose "HKLM:\$RegKey1"
		Write-Verbose "RegSubKey1 = $RegSubKey1"
		New-Item -Path "HKLM:\$RegKey1"
		New-Item -Path "HKLM:\$RegKey1" -Name "$RegSubKey1"
		New-ItemProperty -Path "HKLM:\$RegKeyTotal1" -Name "$RegSubKeyWord1" -Value "$RegSubKeyWord1Value" -PropertyType DWord
		}
	ELSE 	{
			Write-Output "$RegKey1 Key already exists"
			$TestPath2 = Test-Path "HKLM:\$RegKeyTotal1"
			Write-Verbose "TestPath2 = $TestPath2"
			If ($TestPath2 -eq $False)
				{
				Write-Output "Regkey $RegKeyTotal1 Doesn't exist, it is being created"
				New-Item -Path "HKLM:\$RegKey1" -Name "$RegSubKey1"
				New-ItemProperty -Path "HKLM:\$RegKeyTotal1" -Name "$RegSubKeyWord1" -Value "$RegSubKeyWord1Value" -PropertyType DWord
				}
			ELSE 	{
                    Write-Output "$RegKeyTotal1 Key already exists"
					Write-Verbose "RegKeyTotal1 = $RegKeyTotal1"
					Write-Verbose "RegSubKeyWord1 = $RegSubKeyWord1"
					Write-Verbose "Test-RegistryValue -Path HKLM\$RegKeyTotal1 -Value $RegSubKeyWord1"
					$TestSubKeyWord = Test-RegistryValue -Path "Registry::HKLM\$RegKeyTotal1" -Value "$RegSubKeyWord1"
					Write-Verbose "TestSubKeyWord = $TestSubKeyWord"
					If ($TestSubKeyWord -eq $True) 
						{
						Write-Output "Regkey $RegSubKeyWord1 already exist"
						}
					ELSE	{
							Write-Output "Regkey $RegSubKeyWord1 Doesn't exist, it is being created"
							New-ItemProperty -Path "HKLM:\$RegKeyTotal1" -Name "$RegSubKeyWord1" -Value "$RegSubKeyWord1Value" -PropertyType DWord
							}
					}
			}	
	}


# Windows 10 Disable Upgrade
$Key1 = 'SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate'
$SubKey1 = 'OSUpgrade'
$SubKeyWord1 = 'AllowOSUpgrade'
$SubKeyWord1Value = '0'

Test-ChangeRegKey -RegKey1 "$Key1" -RegSubKey1 "$SubKey1" -RegSubKeyWord1 "$SubKeyWord1" -RegSubKeyWord1Value "$SubKeyWord1Value"

# Windows 10 Disable Upgrade
$Key1 = 'SOFTWARE\Policies\Microsoft\Windows'
$SubKey1 = 'GWX'
$SubKeyWord1 = 'DisableGWX'
$SubKeyWord1Value = '1'
Test-ChangeRegKey -RegKey1 "$Key1" -RegSubKey1 "$SubKey1" -RegSubKeyWord1 "$SubKeyWord1" -RegSubKeyWord1Value "$SubKeyWord1Value"