1

In order to find an installed MSI file GUID in a remote VM - I'm using the following command inside of Invoke-Command:
Get-WmiObject Win32_Product | Where-Object {$_.Name -eq "Application Name"}
This command shows in it's output an identifier number.
I know, I should add one more thing to this command in order to get only the GUID but I don't know how...

Now, I need to compare between this GUID to a GUID of a new MSI file I got for an installation.

This mean that:
if the GUID of the new file is older - I'll do nothing
if the GUID of the new file is equal - I'll do nothing
if the GUID of the new file is newer - I'll do an upgrade OR uninstall-install process...

So, In order to compare between the installed MSI's GUID and a new MSI file's GUID:
What will be the exact PowerShell command to find the GUID of the new MSI file?

Hiddai
  • 25
  • 6
  • If you want to upgrade our application there is a means to do so built into MSI. It is called [major upgrades](https://stackoverflow.com/a/23396011/129130). Here is [more on the topic](https://stackoverflow.com/a/50552215/129130). – Stein Åsmul Oct 18 '20 at 10:44
  • Using Powershell to retrieve product code, different methods: 1) [Run MSI session](https://adamrushuk.github.io/get-product-id-guid-directly-from-msi-file/), 2) [Open MSI database file](https://www.reddit.com/r/AskGreg/comments/2hxbw6/powershell_get_product_code_from_msi_file/). I don't use Powershell much. I think it is a bit "high line noise". – Stein Åsmul Oct 18 '20 at 11:53

2 Answers2

1

If I understand correctly you want to find the product GUID of an MSI that is not currently installed? I hope that is a correct understanding of what you ask. If you need to automatically get the product GUID from code, that is also possible. There is a full, standalone VBScript here which you can drag-and-drop an MSI file onto to retrieve the product code.

You can find the product code by opening the MSI with a suitable viewer - for example Orca, the Microsoft SDK tool for MSI packages. If you have Visual Studio installed, try searching for Orca-x86_en-us.msi - under Program Files (x86) - and install it. Then find Orca in the start menu. You can also right click MSI files to open them with Orca - just select: "Edit with Orca". Then you can find the product GUID in the Property table.

Orca

Here is an answer on the topic of MSI viewers (several alternatives, but Orca is the best overall): How can I compare the content of two (or more) MSI files?


There is a Powershell module for MSI: https://github.com/heaths/psmsi


Links:

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140
0

I installed a Carbon library both in the remote VM and in my pc in "C:\Program Files\WindowsPowerShell\Modules" I then execute the following Command:

[string] $newMSIProductCode = (Get-CMsi -Path "C:\appName.msi").ProductVersion
[string] $newMSIProductCodeGUID = (Get-CMsi -Path "C:\appName.msi").ProductCode.Guid
$newMSIProductCode = $newMSIProductCode -replace '\.',''


Enter-PSSession -Computer $computer -Credential $credentials
Invoke-Command -Computer $computer -Credential $credentials -ScriptBlock {

   [string] $installedMSIProductCode = (Get-CProgramInstallInfo -Name "app name").DisplayVersion
   $installedMSIProductCodeGUID = (Get-CProgramInstallInfo -Name "app name").ProductCode.Guid
   [long] $installedMSIProductCode = $installedMSIProductCode -replace '\.',''

   if ($Using:$newMSIProductCodeGUID -gt $installedR10ServerBuildProductCode)
   {
      //TO-DO 
   }
}
Hiddai
  • 25
  • 6