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?
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
}
}