AnalysisServices

StartStopAnalysisServices powerShell scripts

This power shell scripts which help to stop or start analysis server based on requirement as this service is a pay as you use.

This scripts help to reduce the project and company cost .

param(
    [Parameter(Mandatory=$True)]
    [string]$AasAction,
     
    [Parameter(Mandatory=$True)]
    [string]$ResourceGroupName,
 
    [Parameter(Mandatory=$True)]
    [string[]]$AnalysisServerNames
)

foreach ($AnalysisServerName in $AnalysisServerNames)  
{
    Write-Output "Loop Running for Running for $($AnalysisServerName)"

    $myAzureAnalysisServer = Get-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
    if (!$myAzureAnalysisServer)
    {
        Write-Error "$($AnalysisServerName) not found in $($ResourceGroupName)"
        return
    }
    else
    {
        Write-Output "Current status of $($AnalysisServerName): $($myAzureAnalysisServer.State)"
    }

    #if (($AasAction -eq "Start" -And $myAzureAnalysisServer.State -eq "Succeeded") -Or ($AasAction -eq "Stop" -And $myAzureAnalysisServer.State -eq "Paused"))
    #{
     #   Write-Error "Cannot $($AasAction) $($AnalysisServerName) while the status is $($myAzureAnalysisServer.State)"
        
    #}
    # Resume Azure Analysis Services
    if (($AasAction -eq "Start" -And $myAzureAnalysisServer.State -eq "Paused"))
    {
        Write-Output "Now starting $($AnalysisServerName)"
        $null = Resume-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
    }
    # Pause Azure Analysis Services
    elseif(($AasAction -eq "Stop" -And $myAzureAnalysisServer.State -eq "Succeeded"))
    {
        Write-Output "Now stopping $($AnalysisServerName)"
        $null = Suspend-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top