Last active
August 29, 2015 14:07
-
-
Save btm/23aad6661908b00ad752 to your computer and use it in GitHub Desktop.
Use ruby to search Windows Updates for KB2918614
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
require 'rubygems' | |
require 'win32ole' | |
kb = "KB2918614" | |
start_time = Time.now | |
puts "Starting search for #{kb} at #{start_time}" | |
update_session = WIN32OLE.new("Microsoft.Update.Session") | |
update_searcher = update_session.CreateUpdateSearcher | |
update_searcher.Search('IsHidden=1 and IsInstalled=1') | |
total_count = update_searcher.GetTotalHistoryCount | |
puts "Found #{total_count} updates" | |
update_collection = update_searcher.QueryHistory(0, total_count) | |
update_collection.each do |item| | |
if item.Title =~ /#{kb}/ | |
puts "#{kb} is installed" | |
# break # optionally bail out immediately for a slightly faster return | |
end | |
end | |
elapsed_time = Time.now - start_time | |
puts "Completed search in #{elapsed_time} seconds" |
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
PS C:\Users\Administrator> ruby .\kb.rb | |
Starting search for KB2918614 at 2014-10-13 18:10:25 -0700 | |
Found 199 updates | |
KB2918614 is installed | |
Completed search in 10.609375 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment