Merge rewrite_hide_update branch

This commit is contained in:
Yorick Barbanneau 2016-01-21 15:08:37 +01:00
commit b7ef1b0951
2 changed files with 35 additions and 11 deletions

View file

@ -22,8 +22,9 @@ and cut your Little Pony head.
* 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~~ *check rewrite_hide_update branch* <<<<<<< HEAD
* ~~Speed up hide_update~~ *check rewrite_hide_update branch* * ~~Update the windows update list to hide kb that aren't yet listed~~
* ~~Speed up hide_update~~
* **Tell me** * **Tell me**
#License #License

View file

@ -9,20 +9,18 @@ $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)
<<<<<<< HEAD
Foreach ($update in $result.Updates) { Foreach ($update in $result.Updates) {
$found = 0 $found = 0
$kb | Foreach { $kb | Foreach {
@ -37,8 +35,29 @@ function hide_update() {
} }
} }
} }
=======
Foreach ($kb in $kbList){
Write-Host -NoNewline -ForegroundColor White "Hide $kb : "
$id = $kb.Replace("KB","")
$found = 0
Foreach ($update in $result.Updates) {
if ($update.KBArticleIDs -match $id) {
$found = 1
if (!$update.IsHidden) {
$update.IsHidden = "True"
Write-Host -ForegroundColor green "Hidden"
}
else {
Write-Host -ForegroundColor Yellow "Already hidden"
}
}
} }
if (!$found){ Write-Host -ForegroundColor Red "Not found"} if (!$found){ Write-Host -ForegroundColor Red "Not found"}
>>>>>>> rewrite_hide_update
}
}
if (stop-process -name GWX -Force -ErrorAction SilentlyContinue) {
Write-Host "GWX process stopped ..."
} }
Foreach($kbID in $kbIDs){ Foreach($kbID in $kbIDs){
@ -47,7 +66,7 @@ Foreach($kbID in $kbIDs){
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
Do Do
{ {
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
@ -62,5 +81,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