Main example
Alternative: read the registry
# Installed programs, read from the registry (no side effects)
$uninstallPath = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
Get-ItemProperty -Path $uninstallPath -ErrorAction SilentlyContinue |
Where-Object -FilterScript { $_.DisplayName } |
Select-Object -Property DisplayName, DisplayVersion, Publisher, InstallDate |
Sort-Object -Property DisplayNameWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above).
Examples
List instances
# All instances of Win32_Product, with the main properties
Get-CimInstance -ClassName Win32_Product |
Select-Object -Property Name, Version, Vendor, InstallDate, IdentifyingNumberWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above).
Filter with WQL
# WQL filter evaluated by the provider: products whose name starts with Microsoft
Get-CimInstance -ClassName Win32_Product -Filter "Name LIKE 'Microsoft%'" |
Select-Object -Property Name, Version, Vendor, InstallDate, IdentifyingNumberWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above).
Query a remote computer (CIM session)
review before running# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
Get-CimInstance -CimSession $cimSession -ClassName Win32_Product |
Select-Object -Property Name, Version, Vendor, InstallDate, IdentifyingNumber
} finally {
Remove-CimSession -CimSession $cimSession
}Warning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above).
Show the class structure
# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_Product
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, Flags
# Methods of the class
$cimClass.CimClassMethods |
Select-Object -Property Name, ReturnTypeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above).
Properties
| Name | Type | Access | Description |
|---|---|---|---|
| IdentifyingNumber# key | string | read | Product identification, such as a serial number on software or a die number on a hardware chip. For Windows Installer, this is the product code GUID. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| Name# key | string | read | Commonly used product name. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| Version# key | string | read | Product version information. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| Vendor# | string | read | Name of the product supplier or manufacturer. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| Caption# | string | read | Short description of the product, in one line. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| Description# | string | read | Description of the product. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| InstallDate# | string | read | Date the product was installed, as a string in the form YYYYMMDD. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| InstallLocation# | string | read | Location of the installed product. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| InstallSource# | string | read | Location from which the product was installed. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| LocalPackage# | string | read | Location of the locally cached installation package for the product. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| PackageName# | string | read | Name of the installation package, usually the .msi file name. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| PackageCode# | string | read | GUID identifying the installation package. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
| Language# | string | read | Language code of the product, as a Windows language identifier. CodeWarning. Avoid: every enumeration of Win32_Product triggers the consistency check, and sometimes the repair, of every installed MSI package. It is slow, writes MsiInstaller events to the Application log and can change the system. Read the registry instead (example above). |
Methods
Install static#
Installs a Windows Installer package.
uint32 Install(
[in] string PackageLocation,
[in] string Options,
[in] boolean AllUsers
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| PackageLocation | string | in | Location of the Windows Installer package (.msi). |
| Options | string | in | Command-line options passed to Windows Installer, as property=value pairs. |
| AllUsers | boolean | in | If true, the package is installed or advertised for all users of the computer. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Install method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
$methodParameters = @{
ClassName = 'Win32_Product'
MethodName = 'Install'
Arguments = @{
PackageLocation = 'Example'
Options = 'Example'
AllUsers = $false
}
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Admin static#
Installs a package as an administrative image on a network location.
uint32 Admin(
[in] string PackageLocation,
[in] string TargetLocation,
[in] string Options
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| PackageLocation | string | in | Location of the Windows Installer package (.msi). |
| TargetLocation | string | in | Network location of the administrative image. |
| Options | string | in | Command-line options passed to Windows Installer, as property=value pairs. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Admin method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
$methodParameters = @{
ClassName = 'Win32_Product'
MethodName = 'Admin'
Arguments = @{
PackageLocation = 'Example'
TargetLocation = 'Example'
Options = 'Example'
}
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Advertise static#
Advertises a package, which makes it available for installation on first use.
uint32 Advertise(
[in] string PackageLocation,
[in] string Options,
[in] boolean AllUsers
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| PackageLocation | string | in | Location of the Windows Installer package (.msi). |
| Options | string | in | Command-line options passed to Windows Installer, as property=value pairs. |
| AllUsers | boolean | in | If true, the package is installed or advertised for all users of the computer. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Advertise method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
$methodParameters = @{
ClassName = 'Win32_Product'
MethodName = 'Advertise'
Arguments = @{
PackageLocation = 'Example'
Options = 'Example'
AllUsers = $false
}
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Reinstall #
Reinstalls the product.
uint32 Reinstall([in] uint16 ReinstallMode);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| ReinstallMode | uint16 | in | Reinstallation mode, such as repairing missing files or all files. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Reinstall method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Product -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Reinstall'
Arguments = @{ ReinstallMode = 0 }
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Uninstall #
Uninstalls the product.
uint32 Uninstall();Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Uninstall method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Product -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Uninstall'
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Configure #
Configures the installation state of the product.
uint32 Configure(
[in] sint16 InstallState,
[in] uint16 InstallLevel,
[in] string Options
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| InstallState | sint16 | in | Requested installation state. |
| InstallLevel | uint16 | in | Installation level, which selects the features to install. |
| Options | string | in | Command-line options passed to Windows Installer, as property=value pairs. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Configure method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Product -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Configure'
Arguments = @{
InstallState = 0
InstallLevel = 0
Options = 'Example'
}
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Upgrade #
Upgrades the product with a new package.
uint32 Upgrade([in] string PackageLocation, [in] string Options);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| PackageLocation | string | in | Location of the Windows Installer package (.msi). |
| Options | string | in | Command-line options passed to Windows Installer, as property=value pairs. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| Other | Other | Windows Installer error code returned by the operation. |
Call the Upgrade method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Product -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Upgrade'
Arguments = @{
PackageLocation = 'Example'
Options = 'Example'
}
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Remarks
The class is provided by the MSI provider (MSIProv) and lists only the products installed with Windows Installer; programs installed otherwise do not appear.
Enumerating Win32_Product starts a consistency check of every installed MSI package, which can repair a package and which writes MsiInstaller events (event 1035) in the Application log. The enumeration is slow. To list installed programs, read the Uninstall registry keys instead.
Inheritance
Superclass chain
- CIM_Product
- Win32_Product
Known subclasses
No known subclass.
Requirements
- Namespace
- root/cimv2
- Minimum client
- Windows Vista
- Minimum server
- Windows Server 2008
- Provider
- MSIProv
Class qualifiers
Dynamic Provider("MSIProv")
Microsoft source
Entry written by WMI Explorer.