Syntax error How to retrieve the MSI package product code using PowerShell?

How to retrieve the MSI package product code using PowerShell?



You can retrieve the MSI installed packaged product code on the windows OS using PowerShell with Get-Package or Get-WmiObject command.

In this example, we will retrieve the product code of 7-zip.

Get-Package -Name '7-Zip 19.00 (x64 edition)' | fl *

You can use the tagid or mentioned properties to filter the product code.

To retrieve the package from the remote computer using the Get-Package method, use InvokeCommand.

Invoke-Command -ComputerName TestMachine -ScriptBlock{
   (Get-Package -Name '7-Zip 19.00 (x64 edition)').TagID
}

Another way to retrieve the product code is by using the WMI method as shown below.

PS C:\> $product = Get-WmiObject win32_product | where{$_.name -
eq "7-Zip 19.00 (x64 edition)"}
PS C:\> $product.IdentifyingNumber

Output

To get the output from the remote computer, just specify the -ComputerName parameter.

$product = Get-WmiObject win32_product -ComputerName
TestMachine1, Testmachine2 | where{$_.name -eq "7-Zip 19.00 (x64 edition)"}
$product.IdentifyingNumber
Updated on: 2021-08-31T11:28:17+05:30

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements