Scripts to keep windows 10 away.

CLC

Well-Known Member
Reaction score
320
Location
Central Minnesota USA
EDIT: Script provided by @pcpete , Thanks!!

Code:
#this script has 4 main parts: first it checks that you are running this from an admin console;
#it checks if the update is installed; third, if it is installed it removes it; forth
#it will hide the update so it does not reinstall

#the only option the needs to be set is the hotfixid you want removed as set below
#it is currently set to KB3035583, but can be change to check for any hotfix

$hotfixid = "kb3035583"


# this first funciton checks if you are running from an admin console
function check-admin{
    $User = [Security.Principal.WindowsIdentity]::GetCurrent()
    $Role = (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

    if($Role -eq $false){
        write-host "-you will need run this script from an elevated powershell console, the script will now exit"
    }
    $result = $role
    $result
}

#this function checks if the update is installed. if installed it returns $True
function check-installed {
    #we disable error messages for this part of the function. since the logic depends on creating a possible error and it is expected
    $ErrorActionPreference = "silentlycontinue"
    write-host "-checking if $hotfixid is currently installed"
    $isthere = (Get-HotFix $hotfixid)
    if ($isthere.hotfixid -eq $hotfixid){
        #if installed it will return $True
        $result = $true
    }
    else {
        #if not installed it will return $False
        $result = $false
    }
    $result
}

#this is the function that removes the hotfix
function remove-hotfix{
    $hotfixformat = $hotfixid.substring(0,2)+":"+$hotfixid.substring(2)
    wusa /uninstall /$hotfixformat /quiet /norestart
}

#used code from http://www.powershellmagazine.com/2014/03/19/how-to-view-and-restore-hidden-windows-updates-with-powershell/ for the next two functions

function find-hotfixes{ 
    try {
        Write-host "-querying Windows update"
        $Session = New-Object -ComObject Microsoft.Update.Session     
        $Searcher = $Session.CreateUpdateSearcher()     
        $Criteria = "IsInstalled=0 and DeploymentAction='Installation' or IsPresent=1 and DeploymentAction='Uninstallation' or IsInstalled=1 and DeploymentAction='Installation' and RebootRequired=1 or IsInstalled=0 and DeploymentAction='Uninstallation' and RebootRequired=1"   
        $SearchResult = $Searcher.Search($Criteria)   
        $SearchResult.Updates
    } catch {
        Write-Warning -Message "-Failed to query Windows Update because $($_.Exception.Message)"
    }
}

Function Set-WindowsHiddenUpdate {

    [Cmdletbinding()]

    Param(
        [Parameter(ValueFromPipeline=$true,Mandatory=$true)]
        [System.__ComObject[]]$Update,

        [Parameter(Mandatory=$true)]
        [boolean]$Hide
    )

    Process {
        $Update | ForEach-Object -Process {
            if (($_.pstypenames)[0] -eq 'System.__ComObject#{c1c2f21a-d2f4-4902-b5c6-8a081c19a890}') {
                try {
                    $_.isHidden = $Hide
                    Write-Host "-hiding $($_.Title)"
                }
                catch {
                    Write-Host "-Failed to perform action because $($_.Exception.Message)"
                }
            } else {
                Write-Warning -Message "Ignoring object submitted"
            }
        }
    }
}


#this first part uses check-admin function to see if the script can continue
if (check-admin){

    #first checks to see if hotfix is installed, if it is it removes it
    if (check-installed){
        write-host "-currently removing $hotfixid"
        remove-hotfix
    }
    else{
        write-host "-hotfix $hotfixid does not appear to be installed"
    }

    find-hotfixes | Where-Object {$_.title -match $hotfixid}  |  Set-WindowsHiddenUpdate -hide $true -Verbose
}
 
Last edited:
you're welcome. I have been trying to practice learning Powershell everyday with the hopes of getting better. This was the perfect fun script for me to try.
 
You need to save it as a .ps1 file.
You can run it as administrator on a local machine like so:

Open cmd as admin then put this in.
powershell.exe -f C:\example.ps1
 
You need to save it as a .ps1 file.
You can run it as administrator on a local machine like so:

Open cmd as admin then put this in.
powershell.exe -f C:\example.ps1

Cool! I did not know you could run it from CMD, I thought you had to run it from a powershell console. The cool thing about this is you can use a batch script to encapsulate the ps1 script to run it easlily
 
Last edited:
  • Like
Reactions: CLC
you could also change the script execution policy of powershell to run the script then turn it back to default.
Code:
@echo off

powershell.exe Set-ExecutionPolicy unrestricted -force >null
powershell.exe -f c:\script.ps1
powershell.exe Set-ExecutionPolicy default -force
set /p temp="press enter to close window"

if you notice on the following line I redirected the output because it gave me an error saying script exectuion was not set, but it changed it anyways and worked like I would hope
Code:
powershell.exe Set-ExecutionPolicy unrestricted -force >null
 
Last edited:
I just made a batch script that will run the powershell script with one click. It changes the powershell script execution policy temporarily to allow the script to run, then runs the disable 10 powershell script, then turns the script execution policy back to default.. This way all you need to do is run the bat script as admin with one click
 

Attachments

I'm getting "cannot be loaded because the extension of scripts is disabled on this system." Is this CryptoMonitor or something else?
 
I'm getting "cannot be loaded because the extension of scripts is disabled on this system." Is this CryptoMonitor or something else?
did you r-click, "run as admin" on the batch file or run the powershell script directly?
 
Did CLC's method in post #8.

You need to save it as a .ps1 file.
You can run it as administrator on a local machine like so:

Open cmd as admin then put this in.
powershell.exe -f C:\example.ps1
 
That is because by default you cannot run powershell scripts on a desktop OS without allowing it. if you download the zip file in post #12 included in the batch file, it has a command to enable scripts to be run, then runs the ps1 script, then disables scripts back to default. It is just a slight variation on how CLC was doing it.
 
  • Like
Reactions: CLC
I just made a batch script that will run the powershell script with one click. It changes the powershell script execution policy temporarily to allow the script to run, then runs the disable 10 powershell script, then turns the script execution policy back to default.. This way all you need to do is run the bat script as admin with one click


Perfect - thank you!
 
I have noticed even with removing the update the gwx.exe runs in some cases. I am thinking it may be best just to leave the update installed and rename the GWX directory in the system32 directory.
 
Back
Top