Last active
August 29, 2015 14:05
-
-
Save mbrownnycnyc/9075f25350e5e2168899 to your computer and use it in GitHub Desktop.
KB querier and uninstaller (not a real powershell script, just some invocations).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#query for KB on all machines in a given OU (instead of get-adcomputer, try get-content and a file with a list of IPs or hostnames for the same effect) | |
#note that the get-wmiobject is optimized to only request specific hotfixids, before I would request all records are parse client size (ewww) | |
$contents = $( get-adcomputer -filter "objectCategory -eq 'computer'" -SearchBase "OU=New York,DC=contoso,DC=corp" | select-object -expand name ) | |
foreach ($computer in $contents) | |
{ | |
if (fastping $computer) | |
{ | |
get-wmiobject -computer $computer -query "select * from win32_quickfixengineering where hotfixid like '%2982791%' OR hotfixid like '%2970228%' " | select-object csname, hotfixid, installedOn | export-csv -append -NoTypeInformation -noclobber "c:\users\mbrown\desktop\evilkbsliveshere.csv" -Encoding UTF8 | |
} | |
} | |
#invoke a command on all computer objects in an OU, in this case uninstalling KB 2982791 with the wusa.exe tool [check out `dism.exe /online /Get-Features` to have some more fun] | |
Invoke-Command -scriptblock { | |
cmd.exe /c "C:\Windows\system32\wusa.exe /uninstall /kb:2982791 /quiet /norestart" | |
$env:computername + " " + $(Get-Date -format HH:mm:ss) + ": kb2982791 is now uninstalled." | |
} -computername ( get-adcomputer -filter "objectCategory -eq 'computer'" -SearchBase "OU=New York,DC=contoso,DC=corp" | select-object -expand name ) 2>&1 | tee -filepath evilkbcleanup.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment