add check rewrite_hide_update branch
This commit is contained in:
parent
8898441184
commit
e989a65f12
2 changed files with 39 additions and 32 deletions
22
README.md
22
README.md
|
@ -1,29 +1,29 @@
|
||||||
Remove-kb
|
Remove-kb
|
||||||
---------
|
---------
|
||||||
|
|
||||||
A little powershell script to uninstall and hide some updates. I use it to
|
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
|
remove unwanted Windows 10 upgrade. This is a really simple script just for
|
||||||
my need, but I will propably improve it. This script needs Adminitrator's rights.
|
my need, but I will propably improve it. This script needs Adminitrator's rights.
|
||||||
|
|
||||||
There are two parts
|
There are two parts
|
||||||
|
|
||||||
* **launcher.cmd** : a winbatch script to launch powershell one.
|
* **launcher.cmd** : a winbatch script to launch powershell one.
|
||||||
* **remove-kb.ps1** : the powershell script itself.
|
* **remove-kb.ps1** : the powershell script itself.
|
||||||
|
|
||||||
To add or remove uninstalled / hidden KB you nedd to modify $kbIDs
|
To add or remove uninstalled / hidden KB you nedd to modify $kbIDs
|
||||||
variable.
|
variable.
|
||||||
|
|
||||||
Because I'm a Linux fan and this is my first try with powershell
|
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
|
this script is really simple and could not work properly, burn your cat
|
||||||
and cut your Little Pony head.
|
and cut your Little Pony head.
|
||||||
|
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
* Add privilege elevation error when the script is not launched with Administrator's rights
|
* Add privilege elevation error when the script is not launched with Administrator's rights
|
||||||
* Add the possibility to use arguments when calling the script (then ps script could be call from
|
* Add the possibility to use arguments when calling the script (then ps script could be call from
|
||||||
another script)
|
another script)
|
||||||
* Update the windows update list to hide kb that aren't yet listed
|
* ~~Update the windows update list to hide kb that aren't yet listed~~ *check rewrite_hide_update branch*
|
||||||
* Speed up hide_update
|
* ~~Speed up hide_update~~ *check rewrite_hide_update branch*
|
||||||
* **Tell me**
|
* **Tell me**
|
||||||
|
|
||||||
#License
|
#License
|
||||||
|
|
|
@ -9,41 +9,44 @@ $kbIDs=("KB3075249", #telemetry for Win7/8.1
|
||||||
"KB2952664", #Get Windows 10 assistant
|
"KB2952664", #Get Windows 10 assistant
|
||||||
"KB2976978",
|
"KB2976978",
|
||||||
"KB2876229",
|
"KB2876229",
|
||||||
"kb2953664"
|
"KB2953664"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
function hide_update() {
|
function hide_update() {
|
||||||
param($kb)
|
param($kbList)
|
||||||
$i = 0
|
|
||||||
$found = 0
|
|
||||||
Write-Host -NoNewline -ForegroundColor White "Hide $kb : "
|
|
||||||
$session = New-Object -ComObject "Microsoft.Update.Session"
|
$session = New-Object -ComObject "Microsoft.Update.Session"
|
||||||
$searcher = $session.CreateUpdateSearcher()
|
$searcher = $session.CreateUpdateSearcher()
|
||||||
$searcher.Online = $false
|
$searcher.Online = $false
|
||||||
$criteria = "IsInstalled = 0"
|
$criteria = "IsInstalled=0"
|
||||||
$result = $searcher.Search($criteria)
|
$result = $searcher.Search($criteria)
|
||||||
#$result.Updates | Foreach {
|
Foreach ($kb in $kbList){
|
||||||
While ((!$found) -and ($i -lt $result.Updates.Count)) {
|
Write-Host -NoNewline -ForegroundColor White "Hide $kb : "
|
||||||
if ($result.Updates.Item($i).KBArticleIDs -match $kb) {
|
$id = $kb.Replace("KB","")
|
||||||
$found = 1
|
$found = 0
|
||||||
if (!$result.Updates.Item($i).IsHidden) {
|
Foreach ($update in $result.Updates) {
|
||||||
$result.Updates.Item($i).IsHidden = "True"
|
if ($update.KBArticleIDs -match $id) {
|
||||||
Write-Host -ForegroundColor green "Hidden"
|
$found = 1
|
||||||
|
if (!$update.IsHidden) {
|
||||||
|
$update.IsHidden = "True"
|
||||||
|
Write-Host -ForegroundColor green "Hidden"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host -ForegroundColor Yellow "Already hidden"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
Write-Host -ForegroundColor Yellow "Already hidden"
|
if (!$found){ Write-Host -ForegroundColor Red "Not found"}
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++
|
|
||||||
}
|
}
|
||||||
if (!$found){ Write-Host -ForegroundColor Red "Not found"}
|
|
||||||
}
|
}
|
||||||
|
if (stop-process -name GWX -ErrorAction SilentlyContinue) {
|
||||||
|
Write-Output "Killed GWX ..."
|
||||||
|
}
|
||||||
|
|
||||||
Foreach($kbID in $kbIDs){
|
Foreach($kbID in $kbIDs){
|
||||||
$kbNum = $kbID.Replace("KB","")
|
$kbNum = $kbID.Replace("KB","")
|
||||||
Write-Host -NoNewline -ForegroundColor white "Uninstalling $kbID : "
|
Write-Host -NoNewline -ForegroundColor white "Uninstalling $kbID : "
|
||||||
if (Get-HotFix -Id $kbID -ErrorAction SilentlyContinue)){
|
if (Get-HotFix -Id $kbID -ErrorAction SilentlyContinue){
|
||||||
Write-Host -NoNewline -ForegroundColor DarkGreen "found! "
|
Write-Host -NoNewline -ForegroundColor DarkGreen "found! "
|
||||||
Write-Host -Nonewline -ForegroundColor white "removing ... "
|
Write-Host -Nonewline -ForegroundColor white "removing ... "
|
||||||
wusa.exe /uninstall /KB:$kbNum /norestart /quiet /log:wsua.log
|
wusa.exe /uninstall /KB:$kbNum /norestart /quiet /log:wsua.log
|
||||||
|
@ -61,5 +64,9 @@ Foreach($kbID in $kbIDs){
|
||||||
else {
|
else {
|
||||||
Write-Host -ForegroundColor Yellow ("Not installed")
|
Write-Host -ForegroundColor Yellow ("Not installed")
|
||||||
}
|
}
|
||||||
hide_update $kbNum
|
|
||||||
}
|
}
|
||||||
|
Write-Host "`n Wainting ..."
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
Write-Host "`nHiding Updates"
|
||||||
|
Write-Host "--------------`n"
|
||||||
|
hide_update $kbIDs
|
||||||
|
|
Reference in a new issue