Skip to content

Instantly share code, notes, and snippets.

@DaveRuijter
Created November 19, 2018 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveRuijter/5f2a410847164ab33d75f69ed3f835be to your computer and use it in GitHub Desktop.
Save DaveRuijter/5f2a410847164ab33d75f69ed3f835be to your computer and use it in GitHub Desktop.
PowerShell script that enables resuming of an Azure Power BI Embedded Capacity.
<#
.SYNOPSIS
Resume an Azure Power BI Embedded Capacity using Azure Automation.
.DESCRIPTION
This Azure Automation runbook enables resuming 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=$true)]
[string] $resourceGroupName,
[parameter(Mandatory=$false)]
[string] $azureRunAsConnectionName = "AzureRunAsConnection",
[parameter(Mandatory=$true)]
[string] $capacityName
)
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 -eq "Paused")
{
Write-Output "PBI Capacity was paused. Resuming!" | timestamp
$pbiEmbCap = Resume-AzureRmPowerBIEmbeddedCapacity -Name $pbiEmbCap.Name -ResourceGroupName $resourceGroupName
Write-Output "PBI Capacity resumed." | timestamp
$pbiEmbCap = Get-AzureRmPowerBIEmbeddedCapacity -ResourceGroupName $resourceGroupName -Name $capacityName
Write-Output "Current PBI Capacity state: $($pbiEmbCap.State), pricing tier: $($pbiEmbCap.Sku)" | timestamp
}
else
{
Write-Output "PBI Capacity already started!" | timestamp
}
Write-Output "Script finished." | timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment