Public/Get-P1MsiInstall.ps1

function Get-P1MsiInstall {
    <#
    .Synopsis
    Get all PlannerOne installation done with MSI.
 
    .Description
    Read Windows registry to get all PlannerOne unsintall keys.
 
    .Parameter OnlyServer
    Display only server installation.
     
    .Parameter InstallLocation
    The MSI install location to filter
     
    #>

    [cmdletbinding()]
    param(
        [switch] $OnlyServer,
        [string] $InstallLocation
    )    
    Process {
        $Pattern = "^PlannerOne*"
        if ($OnlyServer) {
            $Pattern = "^PlannerOne.for.Dynamics.NAV*"
        }

        if (!$InstallLocation) {
            $installs = gci "hklm:\software\microsoft\windows\currentversion\uninstall" | foreach { gp $_.PSPath } | select DisplayName,DisplayVersion,InstallDate,Publisher,PSChildName,InstallLocation | where { $_.DisplayName -match $Pattern }
            if ($installs -eq $null) {
                $installs = gci "hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall" | foreach { gp $_.PSPath } | select DisplayName,DisplayVersion,InstallDate,Publisher,PSChildName,InstallLocation | where { $_.DisplayName -match $Pattern }
            }
        } else {
            $installs = gci "hklm:\software\microsoft\windows\currentversion\uninstall" | foreach { gp $_.PSPath } | select DisplayName,DisplayVersion,InstallDate,Publisher,PSChildName,InstallLocation | where { $_.DisplayName -match $Pattern -AND $_.InstallLocation -eq $InstallLocation }
            if ($installs -eq $null) {
                $installs = gci "hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall" | foreach { gp $_.PSPath } | select DisplayName,DisplayVersion,InstallDate,Publisher,PSChildName,InstallLocation | where { $_.DisplayName -match $Pattern -AND $_.InstallLocation -eq $InstallLocation }
            }
        }

        return $installs
    }
}