/pbimonitor

Primary LanguagePowerShellMIT LicenseMIT

Intro

For more information please watch the session PBI Monitoring 101 (slides here)

This project aims to provide a solution to collect activity & catalog data from your Power BI tenant using powershell scripts and a Power BI templates to analyse all this data.

You can deploy the powershell scripts in two ways:

Requirements

Ensure you have the propper permissions

Create a Service Principal & Security Group

On Azure Active Directory:

  1. Go to "App Registrations" select "New App" and leave the default options
  2. Generate a new "Client Secret" on "Certificates & secrets" and save the Secret text
  3. Save the App Id & Tenant Id on the overview page of the service principal
  4. Create a new Security Group on Azure Active Directory and add the Service Principal above as member
  5. Optionally add the following API's on "API Permissions" and Administrator grant to get the license & user info data:
    • User.Read.All
    • Organization.Read.All

image

Authorize the Service Principal on PowerBI Tenant

As a Power BI Administrator go to the Power BI Tenant Settings and authorize the Security Group on the following tenant settings:

  • "Allow service principals to use read-only Power BI admin APIs"
  • "Allow service principals to use Power BI APIs"
  • "Enhance admin APIs responses with detailed metadata"
  • "Enhance admin APIs responses with DAX and mashup expressions"

image

Setup - Local PowerShell

image

Install Required PowerShell Modules (as Administrator)

Install-Module -Name MicrosoftPowerBIMgmt -RequiredVersion 1.2.1026

Change the Config.json

Open the Config File and write the saved properties from the Service Principal:

  • AppId
  • AppSecret
  • Tenant Id

image

Run

The file Fetch - Run is the entry point to call the other scripts.

Ensure Fetch - Run is targeting the proper configuration file (parameter "configFilePath") and you can also control which scripts are executed on the parameter $scriptsToRun

Run Fetch - Run

Open the Power BI Report

Open the Power BI Template file and change the parameter "DataLocation" to the data folder.

Setup - As an Azure Function

image

On an Azure Subscription create a resource group:

image

All the resources should be created in the same region as the Power BI Tenant, to see the region of the Power BI tenant go to the About page on powerbi.com:

image

Inside the Resource Group start a Function App Creation Wizard

image

Basics

  • Runtime - "PowerShell Core"
  • Version 7.0

image

Hosting

  • Storage Account - Create a new storage account to hold the data collected from the Azure Function
  • Plan Type - Consumption, oon a large Power BI tenant a dedicated plan might be needed because on consumption the functions have a 10 minute timeout

image

Monitoring

  • Create a new AppInsights for logging & monitoring execution

image

In the end the resource group shall have the following resources:

image

To deploy the Azure Function code you need to run the script Tool - PublishAzureFunction. This script will create a zip file ready to deploy to the Azure Function:

image image

Open the Azure Function page, go to "Advanced Tools" and click "Go ➔" This will take you to a page called "Kudu Services"

image

Go to "Tools" -> "Zip Push Deploy" and drag & drop the file AzureFunction.zip:

image image

Confirm if the deploy was successful:

image

Go back to the Azure Function page and click on "Configuration", the following configuration settings must shall be created:

Setting Value
PBIMONITOR_AppDataPath C:\home\data\pbimonitor
PBIMONITOR_ScriptsPath C:\home\site\wwwroot\Scripts
PBIMONITOR_ServicePrincipalId [YOUR SERVICE PRINCIPAL ID]
PBIMONITOR_ServicePrincipalSecret [YOUR SERVICE PRINCIPAL SECRET]
PBIMONITOR_ServicePrincipalTenantId [YOUR TENANT ID]
PBIMONITOR_ServicePrincipalEnvironment Public
PBIMONITOR_StorageContainerName pbimonitor
PBIMONITOR_StorageRootPath raw

image image

The function should be ready to run, go to the function page and open the “AuditsTimer” and Run it:

image image

A change to the Power BI file is required to work with the Blob Storage, open the PBIX and the Power Query window, go to the query "FilesProxy" and uncomment the queries "* from BlobStorage":

image

Change the parameter "DataLocation" and write the blob storage name:

image

You'll also need to copy the Access key from the Azure Portal:

image

And then paste it in the "Account key" box in the Azure Blob Storage credentials, which can be found in the Data Source Settings in Power BI Desktop:

image

Power BI Report Template

Open the Power BI Report template PBI - Activity Monitor and set the parameters:

image

image

image

image