In this new blog post we will explain step by step how you can resize, pause and automatically activate Azure PowerBi Embedded in a simple and fast way. For this we will try to capture step by step what the procedure would be, but first of all we must take into account the following necessary starting points:

  • We create a “Resource Group” where we will locate the necessary elements.
  • We will create a “Storage Account” to host logs and scripts.
  • We will create a “Function App” to automate the tasks we need.
  • We will create an “App Registration” to grant permissions on the PowerBI instance.
  • We will write some small scripts in PowerShell that will perform the tasks of resizing, pausing and activating PowerBI.

Now we can begin to explain step by step the procedure to follow:

1.- We assume that we have already created an instance of PowerBI Embedded in Azure and we have logged into the Azure portal.

2.- We create a “Resource Group” to host the different elements, in this case it will be called rg_auto:

3.- From within the “Resource Group” we will look for and create a “Function App”:

4.- We will define the “Function App” with the following data:

  • App Name: startstoppowerbi (We chose a name)
  • Resource Group: rg_auto (Created previously)
  • OS: Windows (We will use the PowerShell Stack)
  • Hosting Plan: Consumption Plan (We will pay only for the executions made)
  • Runtime Stack: PowerShell Core (Preview)
  • Storage: Select “Create new” and indicate a name for the storage account where the scripts and logs will be saved)
  • Application Insights: We leave the option activated which will help us check for possible problems.

Click on “Create”

5.- The resulting elements will be:

6.- We will give permissions on the PowerBI instance to the newly created “Function App”. In the menu on the left, we look for the “Azure Active Directory” option and click on it:

7.- In the menu on the left of the “Azure Active Directory” blade, click on “App registrations”

8.- We will create a new “App registration” from the button:

9.- We will indicate a name that we can remember later and click on “Register”:

10.- Once it has been created, we will create a secret from “Certificates & secrets“:

11.- Click on “New client secret”:

12.- We indicate a name in the “Description” field and how long we want to:

13.- We copy the value of the secret, since we can only see it at this time before changing the blade, in this case it is: 0FMemcCl1Dpy1z]7Q-+ESD_@3l6+4udS

14.- Click on the Overview option to see the general data and take what we need:

15 .- The necessary data in addition to the secret are:

  • Application (client) ID
  • Directory (tenant) ID

16.- We will open the “Resource Group” that contains the PowerBI Embedded instance, and in this, we will go to the “Access control (IAM)” option:

17.- Click on the “Add a role assignment” button:

18.- We will look for our “App Registration”, we will select it, we will play the role of “Contributor”, and click on “Save”:

19.- In order for the tasks to be executed at the selected times, we must configure the “App Service” in the corresponding time slot. We will return to the “Resource Group” that contains the “App Service” previously created, and we will select it:

20.- Under Configured features, click on “Configuration”:

21.- We add a new configuration by clicking on:

22.- Insert the values ​​of our time zone, and save the configuration:

23.- We restart the “Function App”

24.- Click on the “+” symbol next to Functions to add a new function:

25.- We indicate the option “In-portal” and click on “Continue”:

26.- We indicate the “Timer” option and click on “Create”:

27.- We will see a screen like the following:

28.- Now we will write the code in PowerShell necessary to for example pause the instance of PowerBI Embedded, we will replace the previous code with:

  • # Input bindings are passed in via param block.

param($Timer)

  • # Get the current universal time in the default string format

$currentUTCtime = (Get-Date).ToUniversalTime()

  • # The ‘IsPastDue’ porperty is ‘true’ when the current function invocation is later than scheduled.

if ($Timer.IsPastDue) {

Write-Host “PowerShell timer is running late!}

  • # Write an information log with the current time.

Write-Host “PowerShell timer trigger function ran! TIME: $currentUTCtime”

  • #Connect to Azure:

$azureAplicationId =”XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

$azureTenantId= “XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

$azurePassword = ConvertTo-SecureString “XXXXXXXXXXXXXXXXXXXXXXXXXXXXX” -AsPlainText -Force

$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)

Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal

  • #Service Stop:

Suspend-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName XXXXXXX

  • #State ask

Get-AzPowerBIEmbeddedCapacity

[TimeZoneInfo]::Local

Get-Date -format r

In this script we will need to modify the values ​​that appear in the code with “XXX” for the data collected when we created the “App Registration”, the Resouce Group of the PowerBI instance, and the name of the PowerBI instance:

  • $azureAplicationId =”Application (client) ID
  • $azureTenantId= “Directory (tenant) ID
  • $azurePassword = ConvertTo-SecureString “SECRET” -AsPlainText -Force

Suspend-AzPowerBIEmbeddedCapacity -Name RESOURCE GROUP NAME -ResourceGroupName INSTANCE NAME

29.- Once modified, click on save:

30.- To test it, click on “Run”:

31.- At the bottom a window will open showing the execution log, we should receive a message of the style:

2019-08-21T09:55:41.382 [Information] Executed ‘Functions.TimerTrigger1’ (Succeeded, Id=8a5ca854-7a19-4036-8a58-ce88252fb521)

32.- In the “Activity log” option of the PowerBi instance, we must see the event initiated by the “App Registration”:

And the instance must be in “Paused” state:

33.- To program this shutdown automatically at one hour of your choice, click on the option “Integrate” in our function:

To stop the instance every day at 20:00 hours we would indicate in “cron” format and click on “Save”:

In the “Documentation” link we have more information about it:

34.- In the “Monitor” option of the function, we can see the result of the executions:

Clicking on one of them we will see the details of it:

35.- To start the instance automatically we will create a new function, using the same code as before, and replacing:

  • #Service Stop: Suspend-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName XXXXXXX
  • We change to #Service Start: Resume-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName XXXXXXX

36.- To change the size of the instance we will automatically create a new function, using the same code as before, and replacing:

  • #Service Stop: Suspend-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName XXXXXXX
  • We change to #Change of capacity to A1: Update-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName rg_XXXXXXX -Sku A1. This would be for a size “A1”

– For a “A2” size: #Change of capacity to A2: Update-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName XXXXXXX-Sku A2

– For an “A3” size: #Change capacity to A3: Update-AzPowerBIEmbeddedCapacity -Name XXXXXXX -ResourceGroupName XXXXXXX-Sku A3

– And successively up to the maximum size “A6”

 

37.- For this example we have used as a function trigger, a moment of the day using the option:

But we have other different triggers that can best suit our needs such as:

And many others that you will find in the collection.

About Mariano

Senior technician in electricity and electronics. He is certified in Gk4509 - Big Data on AWS, AWS Certified Solutions Architect - Associate and AWS Certified Solutions Architect - Professional. He began his professional career 15 years ago in Telvent, passing through the positions of monitoring operator, Backoffice, systems administrator, and Service architect. Later, in Tecnocom he worked 3 years as a systems administrator, and finally in 2017 he joined the Enimbos team as Cloud Consultant.