Scheduled scaling of PowerBI Embedded Gen1

I’m assuming you already have:
1. PowerBI Embedded Gen1
2. Automation Account with Hybrid Worker Group and dedicated system user.
Note: The example can be rework to work even without the hybrid worker group.

The idea is to have PowerShell script that can change the capacity of the PowerBI, which can be authenticated with specific system user that would be capacity admin of the PowerBI service and to add the script as Automation Account runbook so scheduling can be created. (let’s say you want the PowerBI Embedded Gen1 to have capacity of A7 during business hours and capacity A3 outside of business hours. (Also please note that Gen2 will have this type of scaling already available within the service’s features)

  1. Go to PowerBI Embedded Gen1 settings “Power BI capacity administrators” and add the system user as a capacity admin. That would be the user that’s authenticated with on your hybrid worker group of the Automation Account. If you wish to run in Azure instead of Hybrid Worker Group you can add the specific authentication on step 2 and runtime on step 4.
  2. Create new Automation Account PowerShell Runbook with the following code:
Param (
    [Parameter(Mandatory = $true)]
    [Parameter(Mandatory = $true)]
    [Parameter(Mandatory = $true)]
    [String]$resourceGroupName ,
    [Parameter(Mandatory = $true)]

$ctx = Set-AzContext -SubscriptionId $subscriptionId
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile;
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile);
$bearer = $profileClient.AcquireAccessToken($ctx.Subscription.TenantId).AccessToken 
$body = '{"sku": {"name": "'+ $scale +'" ,"tier": "PBIE_Azure"}}'
$uri = "" +$subscriptionId+ "/resourceGroups/" +$resourceGroupName+ "/providers/Microsoft.PowerBIDedicated/capacities/"+ $serviceName+ "?api-version=2017-10-01"
$authHeader = "Bearer $bearer"
$header = @{"Authorization"=$authHeader}

Invoke-RestMethod -Method 'Patch' -ContentType 'application/json' -Uri $uri -Body $body -Header $header

Don’t forget to click “Publish”

3. Go to the Automation Account and add schedules. For this example, let’s say we want 2 schedules. One to run at 9am to scale up and one to run at 9pm to scale down.

4. Once you’re done with the schedules in the Automation Account, you can proceed linking them in the PowerShell Runbook. Go to your runbook resources and add the schedules we just created.

First link the schedule that starts at the beginning of the day and configure the parameters and run settings as follows:
SCALE = type which scale you want (i.e. A1 to A8)
SUBSCRIPTIONID = type your subscription id
RESOURCEGROUPNAME = type the name of the resource group, where your PowerBI Embedded Gen1 is located
SERVICENAME = type the name of the PowerBI Embedded Gen1
Run Settings = select your hybrid worker group, or if you’ve edited the authorizations from the POC in step 2 (i.e. you don’t want to run the script from on-premise server) select “Run on Azure”

After you’re ready with the scaling up, repeat this step 4 by adding the schedule for scaling down.

Stay Awesome,

Leave a Reply

Your email address will not be published.