DSCResources/ROACommon/Src/Get-ROAComponentInstallPath.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Get-ROAComponentInstallPath {
<#
    .SYNOPSIS
        Resolves the installation directory of the specified RES ONE Automation component.
#>

    [CmdletBinding()]
    [OutputType([System.String])]
    param (
        [Parameter(Mandatory)]
        [ValidateSet('Agent','Console','Dispatcher')]
        [System.String] $Component
    )
    process {

        $installedProducts = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
                                'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*';
        $resProducts = $installedProducts |
                            Where-Object { $_.DisplayName -match '^RES' -and $_.DisplayName -match 'Automation' }

        if ($Component -eq 'Agent') {

            $resProduct = $resProducts |
                            Where-Object { $_.DisplayName -match 'Agent' }
        }
        elseif ($Component -eq 'Console') {

            $resProduct = $resProducts |
                            Where-Object { $_.DisplayName -notmatch 'Agent' -and $_.DisplayName -notmatch 'Dispatcher' }
        }
        elseif ($Component -eq 'Dispatcher') {

            $resProduct = $resProducts |
                            Where-Object { $_.DisplayName -match 'Dispatcher' }
        }

        return $resProduct.InstallLocation;

    } #end process
} #end function Get-ROAComponentInstallPath