Azurearch Tech

StartStopProdAAS powershell scripts

StartStopProdAAS ps file have particular time frame to start the server in compare to UAT server.

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



$date = Get-Date
$day = [int]$date.day
Write-Host "Set int date........."
Write-Host 'Day of the month........'$day 




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 ready to start $($AnalysisServerName)"
		if ($day -eq 1)
		{ 
			Write-Output "Now starting $($AnalysisServerName)"
			Write-Output "If block for Starting Server for day less than $($day)"
			if ($AnalysisServerName -eq "anlys01")
			{
			$null = Resume-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
			}
			else
			{
			$null = Resume-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
			$null = Set-AzAnalysisServicesServer -sku S9v2 -Name $AnalysisServerName -ResourceGroupName $ResourceGroupName
			}
			
		}
		elseif ($day -ge 2 -And $AnalysisServerName -eq "anlys02")
		{	
			Write-Output "Now starting $($AnalysisServerName)"
			Write-Output "ElseIf block for Starting Server for day greater than $($day)"
			$null = Resume-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
		}
    }
    # Pause Azure Analysis Services
    elseif(($AasAction -eq "Stop" -And $myAzureAnalysisServer.State -eq "Succeeded"))
    {
		Write-Output "Now ready to stop $($AnalysisServerName)"
		if ($day -ge 4)
		{
			Write-Output "Now stopping  $($AnalysisServerName)"
			Write-Output "If block for stopping Server..day greater than $($day)" 
			if ($AnalysisServerName -eq "anlys01")
			{
			$null = Suspend-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
			}
			else
			{
			$null = Set-AzAnalysisServicesServer -sku S8v2 -Name $AnalysisServerName -ResourceGroupName $ResourceGroupName
			$null = Suspend-AzAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
			}
			
		}
		
    }
}

Exit mobile version