Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<#
.SYNOPSIS
Pause/suspend an Azure Power BI Embedded Capacity using Azure Automation.
.DESCRIPTION
This Azure Automation runbook enables pausing/suspending of an Azure Power BI Embedded Capacity.
.PARAMETER resourceGroupName
Name of the resource group to which the capacity is assigned.
.PARAMETER azureRunAsConnectionName
Azure Automation Run As account name. Needs to be able to access the $capacityName.
.PARAMETER capacityName
Azure Power BI Embedded Capacity name.
.EXAMPLE
-resourceGroupName myResourceGroup
-azureRunAsConnectionName AzureRunAsConnection
-capacityName mypowerbipremiumcapacity
.NOTES
Author: Dave Ruijter
Last Updated: Nov 2018
#>
param(
[parameter(Mandatory=$false)]
[string] $resourceGroupName = "rg-neu-powerbi-premium",
[parameter(Mandatory=$false)]
[string] $azureRunAsConnectionName = "AzureRunAsConnection",
[parameter(Mandatory=$false)]
[string] $capacityName = "macawpowerbipremiumcapacity"
)
filter timestamp {"[$(Get-Date -Format G)]: $_"}
Write-Output "Script started." | timestamp
$VerbosePreference = "Continue"
$ErrorActionPreference = "Stop"
#Authenticate with Azure Automation Run As account (service principal)
$runAsConnectionProfile = Get-AutomationConnection -Name $azureRunAsConnectionName
Add-AzureRmAccount -ServicePrincipal -TenantId $runAsConnectionProfile.TenantId -ApplicationId $runAsConnectionProfile.ApplicationId -CertificateThumbprint $runAsConnectionProfile.CertificateThumbprint | Out-Null
Write-Output "Authenticated with Automation Run As Account." | timestamp
# Get the PBI Capacity object
$pbiEmbCap = Get-AzureRmPowerBIEmbeddedCapacity -ResourceGroupName $resourceGroupName -Name $capacityName
Write-Output "PBI Capacity name found: $($pbiEmbCap.Name)" | timestamp
Write-Output "Current PBI Capacity status: $($pbiEmbCap.State), pricing tier: $($pbiEmbCap.Sku)" | timestamp
if($pbiEmbCap.State -ne "Paused")
{
Write-Output "PBI Capacity not paused. Pausing!" | timestamp
$pbiEmbCap = Suspend-AzureRmPowerBIEmbeddedCapacity -Name $pbiEmbCap.Name -ResourceGroupName $resourceGroupName
Write-Output "PBI Capacity paused." | timestamp
$pbiEmbCap = Get-AzureRmPowerBIEmbeddedCapacity -ResourceGroupName $resourceGroupName -Name $capacityName
Write-Output "Current PBI Capacity sate: $($pbiEmbCap.State), pricing tier: $($pbiEmbCap.Sku)" | timestamp
}
else
{
Write-Output "PBI Capacity paused already. Exiting..." | timestamp
}
Write-Output "Script finished." | timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.