
This script query all servers in a specific OU and running on Windows Server 2003 and check if a specific hotfix is installed or not.
Script (with Microsoft Active Directory module loaded : import-module activedirectory) :
$server_list = Get-ADComputer -searchbase "OU=Servers,DC=domain,DC=net" -LDAPFilter "(operatingsystem=Windows Server 2008 R2 Standard)" foreach ($server in $server_list) { $hostname = $server.Name if (Get-WmiObject -Computer $hostname -Class Win32_QuickFixEngineering -Filter "ServicePackInEffect='KB943729'" -erroraction silentlycontinue) { Write-Host "$hostname has KB943729 installed" } else{ Write-Host "Cannot connect to $hostname or KB943729 not installed on $box" } }
Script (with Quest Active Directory module) :
$server_list = Get-QADComputer -SearchRoot "OU=Servers,DC=domain,DC=net" -SearchAttributes @{operatingSystem='Windows Server 2008 R2 Standard'} foreach ($server in $server_list) { $hostname = $server.Name if (Get-WmiObject -Computer $hostname -Class Win32_QuickFixEngineering -Filter "ServicePackInEffect='KB943729'" -erroraction silentlycontinue) { Write-Host "$hostname has KB943729 installed" } else{ Write-Host "Cannot connect to $hostname or KB943729 not installed on $box" } }
Reference
WMI class Win32_QuickFixEngineering description :
The Win32_QuickFixEngineering WMI class represents a small system-wide update, commonly referred to as a quick-fix engineering (QFE) update, applied to the current operating system. Starting with Windows Vista, this class returns only the updates supplied by Component Based Servicing (CBS). These updates are not listed in the registry. Updates supplied by Microsoft Windows Installer (MSI) or the Windows update site (http://update.microsoft.com) are not returned by Win32_QuickFixEngineering.
Windows Server 2003 and Windows XP: Instances of this class represent updates found in two places in the registry:
-
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix
-
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates
The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties and methods are in alphabetic order, not MOF order.
Syntax
[Provider("CIMWin32")]class Win32_QuickFixEngineering : CIM_LogicalElement { string Caption; string CSName; string Description; string FixComments; string HotFixID; datetime InstallDate; string InstalledBy; string InstalledOn; string Name; string ServicePackInEffect; string Status; };
Members
The Win32_QuickFixEngineering class has these types of members:
Properties
The Win32_QuickFixEngineering class has these properties.
- Caption
-
- Data type: string
- Access type: Read-only
Short textual description of the object.
- CSName
-
- Data type: string
- Access type: Read-only
- Qualifiers: MaxLen (256)
Local name of the computer system. The value for this property comes from the CIM_ComputerSystem class.
- Description
-
- Data type: string
- Access type: Read-only
Description of the object.
- FixComments
-
- Data type: string
- Access type: Read-only
Additional comments that relate to the update.
- HotFixID
-
Unique identifier associated with a particular update.
- InstallDate
-
- Data type: datetime
- Access type: Read-only
Object was installed. This property does not require a value to indicate that the object is installed.
- InstalledBy
-
- Data type: string
- Access type: Read-only
Person who installed the update. If this value is unknown, the property is empty.
- InstalledOn
-
- Data type: string
- Access type: Read-only
Date that the update was installed. If this value is unknown, the property is empty.
- Name
-
- Data type: string
- Access type: Read-only
Label by which the object is known. When subclassed, the property can be overridden to be a key property.
- ServicePackInEffect
-
Service pack in effect when the update was applied. If no service pack has been applied, the property takes on the value SP0. If it cannot be determined what service pack was in effect, this property is NULL.
- Status
-
- Data type: string
- Access type: Read-only
Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: “OK”, “Degraded”, and “Pred Fail” (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: “Error”, “Starting”, “Stopping”, and “Service”. The latter, “Service”, can apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither “OK”, nor in one of the other states.
The values are:
- “OK”
- “Error”
- “Degraded”
- “Unknown”
- “Pred Fail”
- “Starting”
- “Stopping”
- “Service”
Remarks
The Win32_QuickFixEngineering class is derived from CIM_LogicalElement.
Because updates are stored in two places, an enumeration of this class can result in duplicates.
Examples
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.
For C++ code examples, see WMI C++ Application Examples.