Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DaveRuijter
Created November 19, 2018 22:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveRuijter/4cb60583da7d9a9dc547b18a01e4e3f9 to your computer and use it in GitHub Desktop.
Save DaveRuijter/4cb60583da7d9a9dc547b18a01e4e3f9 to your computer and use it in GitHub Desktop.
<#
.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
@APhungBSc
Copy link

Hi! Do you have an updated version of this code that uses "Managed identities" for authentication instead of "Run As" since its depreciated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment