Welcome, guest | Sign In | My Account | Store | Cart

This script uses WMI (via Win32::OLE) to retrieve and print out a comma separated list of all installed Windows hotfixes.

Perl, 28 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use warnings;
use strict;
use Win32::OLE('in');
use constant wbemFlagReturnImmediately  => 0x10;
use constant wbemFlagForwardOnly        => 0x20;

getHotfixes(".");

sub getHotfixes {
  my $computer = shift;
  my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection failed.\n";
  my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_QuickFixEngineering","WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);

  foreach my $objItem (in $colItems){
    print "$objItem->{HotFixID}," unless ($objItem->{HotFixID}=~/File 1/);
    #print "Name: $objItem->{Name}\n";
    #print "Description: $objItem->{Description}\n";
    #print "Caption: $objItem->{Caption}\n";
    #print "CS Name: $objItem->{CSName}\n";
    #print "Fix Comments: $objItem->{FixComments}\n";
    #print "Install Date: $objItem->{InstallDate}\n";
    #print "Installed By: $objItem->{InstalledBy}\n";
    #print "Installed On: $objItem->{InstalledOn}\n";
    #print "Service Pack In Effect: $objItem->{ServicePackInEffect}\n";
    #print "Status: $objItem->{Status}\n";
    #print "\n";
  }
}

The getHotfixes() subroutine can be put inside a foreach loop to collect hotfix data from an array of networked machines.

Example: my @servers = ('192.168.1.2', '192.168.1.3', '192.168.1.4', '192.168.1.5'); foreach my $server (@servers){ getHotfixes($server); }