public/Get-ServerMode.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
function Get-ServerMode {
<#
    .SYNOPSIS
    Returns the mode of the SSAS server: Tabular or Multidimensional
 
    .DESCRIPTION
    Returns the mode of the SSAS server: Tabular or Multidimensional
 
    .PARAMETER Server
    Name of the SSAS server, including instance and port if required.
 
    .EXAMPLE
    Get-ServerMode -Server localhost;
 
    Returns 'Tabular'
 
    .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
    (
        [String] [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        $Server
    )
    $returnValue = "";
    try {
        [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") | Out-Null;
        $ssasServer = New-Object Microsoft.AnalysisServices.Server;
        $ssasServer.connect($Server);
        if ($ssasServer.Connected -eq $false) {
            throw "SSAS server $Server does not exist";
        }
        $returnValue = $ssasServer.ServerMode;
        $ssasServer.disconnect();
    } catch {
        throw "SSAS server $Server does not exist";
    }

    return $returnValue;
}