public/Get-AnalysisServicesDeploymentExePath.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function Get-AnalysisServicesDeploymentExePath {
<#
    .SYNOPSIS
    Find path to specific version of Microsoft.AnalysisServices.Deployment.exe
 
    .DESCRIPTION
    Finds the path to specific version of Microsoft.AnalysisServices.Deployment.exe
 
    .PARAMETER Version
    The version of Microsoft.AnalysisServices.Deployment.exe to find.
    Valid values for -Version are:
    * latest: Latest SQL Server version found on agent
    * 150: SQL Server 2019
    * 140: SQL Server 2017
    * 130: SQL Server 2016
    * 120: SQL Server 2014
 
    .EXAMPLE
    Get-AnalysisServicesDeploymentExePath -Version latest
 
    Returns the latest version of Microsoft.AnalysisServices.Deployment.exe
 
    .OUTPUTS
    Returns a string containing the full path to the selected version of Microsoft.AnalysisServices.Deployment.exe
 
    .LINK
    https://github.com/DrJohnT/DeployCube
 
    .NOTES
    Written by (c) Dr. John Tunnicliffe, 2019 https://github.com/DrJohnT/DeployCube
    This PowerShell script is released under the MIT license http://www.opensource.org/licenses/MIT
#>

    [OutputType([string])]
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [ValidateSet('150', '140', '130', '120', '110', 'latest')]
        [string]$Version
    )

    try {
        [string]$ExeName = "Microsoft.AnalysisServices.Deployment.exe";

        $AnalysisServicesDeploymentExes = Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server\$Version" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;

        foreach ($AnalysisServicesDeploymentExe in $AnalysisServicesDeploymentExes) {
            $AnalysisServicesDeploymentExePath = $AnalysisServicesDeploymentExe.FullName;
            $ProductVersion = $AnalysisServicesDeploymentExe.VersionInfo | Select-Object ProductVersion;
            break;
        }

        Write-Verbose "$ExeName $ProductVersion found here $AnalysisServicesDeploymentExePath";
    }
    catch {
        Write-Error "Get-AnalysisServicesDeploymentExePath failed with error $Error";
    }
    return $AnalysisServicesDeploymentExePath;
}