From 19eaa99a3a131210d163b61b51f8341fada1b12d Mon Sep 17 00:00:00 2001 From: Yorick Date: Tue, 19 Jan 2016 14:53:28 +0100 Subject: [PATCH] First public release --- README.md | 32 +++++++++++++++++++++++++++++++ launcher.cmd | 13 +++++++++++++ remove-kb.ps1 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 README.md create mode 100755 launcher.cmd create mode 100755 remove-kb.ps1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..11e5731 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +Remove-kb +--------- + + A little powershell script to uninstall and hide some updates. I use it to + remove unwanted Windows 10 upgrade. this is a really simple script just for + my need, but I propably improve it. This script need Adminitrator right + + There are two part + + * **lancher.cmd** : a winbatch script to launch powershell one. + * **remove-kb.ps1** : the powershell script itself. + + To add or remove uninstalled / hidden KB you nedd to modify $kbIDs + variable. + + Because I'm a Linux fan and this is my first try with powershell + this script is really simple and could not work properly, burn your cat + and cut your Little Pony head. + +#TODO + + * Add privilege elevation error when not launch scrip with Administrator right + * Add possibility of arguments for remove KB (then ps script could be call from + another script) + * Write a function for removing like hide_update + * Update the windows update list to hidde kb than aren't yet listed + * Speed up hide_update + * **Tell me** + +#Licence + +Do what you're whant and fell free to offer me a beer :D diff --git a/launcher.cmd b/launcher.cmd new file mode 100755 index 0000000..8a0efc4 --- /dev/null +++ b/launcher.cmd @@ -0,0 +1,13 @@ +@echo off +cd /d "%~dp0" +REM CMD exectition script for remove-kb.ps1 +echo Change ps execution policy ... +powershell set-executionpolicy unrestricted + +echo . +echo Launch remove-kb script ... +powershell "%~dp0remove-kb.ps1" + +echo REstore ps execution policy ... +powershell set-executionpolicy restricted +PAUSE diff --git a/remove-kb.ps1 b/remove-kb.ps1 new file mode 100755 index 0000000..0e6ec7b --- /dev/null +++ b/remove-kb.ps1 @@ -0,0 +1,53 @@ +$kbIDs=("KB3035583", "KB2952664", "KB3021917", "KB2976978", "KB2876229") + + +function hide_update() { + param($kb) + $i = 0 + $found = 0 + Write-Host -NoNewline -ForegroundColor White "Hide $kb : " + $session = New-Object -ComObject "Microsoft.Update.Session" + $searcher = $session.CreateUpdateSearcher() + $searcher.Online = $false + $criteria = "IsInstalled = 0" + $result = $searcher.Search($criteria) + #$result.Updates | Foreach { + While ((!$found) -and ($i -lt $result.Updates.Count)) { + if ($result.Updates.Item($i).KBArticleIDs -match $kb) { + $found = 1 + if (!$result.Updates.Item($i).IsHidden) { + $result.Updates.Item($i).IsHidden = "True" + Write-Host -ForegroundColor green "Hidden" + } + else { + Write-Host -ForegroundColor Yellow "Already hidden" + } + } + $i++ + } + if (!$found){ Write-Host -ForegroundColor Red "Not found"} +} + +Foreach($kbID in $kbIDs){ + $kbNum = $kbID.Replace("KB","") + Write-Host -NoNewline -ForegroundColor white "Uninstalling $kbID : " + + if ($exist){ + Write-Host -NoNewline -ForegroundColor DarkGreen "found!" -ForegroundColor white "removing ... " + wusa.exe /uninstall /KB:$kbNum /norestart /quiet /log:wsua.log + Do + { + Start-Sleep -Seconds 3 + }while(Invoke-Command -ScriptBlock {Get-Process | Where-Object {$_.name -eq "wusa"}}) + if(Get-HotFix -Id $kbID -ErrorAction SilentlyContinue){ + Write-Host -NoNewline -ForegroundColor Red "Failed" + } + else{ + Write-Host -NoNewline -ForegroundColor Green "Done" + } + } + else { + Write-Host -ForegroundColor Yellow ("Not installed") + } + hide_update $kbNum +}