PowerShell sample scripts

Several self-documenting sample PowerShell scripts that leverage the Power BI REST API are available at the following GitHub repository https://github.com/Azure-Samples/powerbi-powershell.

As shown in the following screenshot, this repository includes PowerShell scripts (.ps1 files) for the refresh of a dataset, the rebinding of a report (to a dataset), and other common use cases:

Power BI REST API samples

In addition to Windows PowerShell or the PowerShell Integrated Scripting Environment (ISE), Azure PowerShell cmdlets must also be installed to execute the REST API scripts. The following links can be used to install the necessary components:

The necessary cmdlets can also be installed from PowerShell via the following commands:

Install-Module AzureRM
Install-Module AzureAD

The variables in each sample advise of the parameters needed to successfully execute the script, such as the client ID of the registered application. The following sample script includes a variable for the client ID of the registered application described earlier and a function for authenticating against Azure Active Directory with this client ID:

$clientId = " FILL ME IN " 
function GetAuthToken
{
$adal = "${env:ProgramFiles}WindowsPowerShellModulesAzureRM.profile4.1.1Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles}WindowsPowerShellModulesAzureRM.profile4.1.1Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceAppIdURI = "https://analysis.windows.net/powerbi/api"
$authority = "https://login.microsoftonline.com/common/oauth2/authorize";
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")
return $authResult
}
$token = GetAuthToken

The sample PowerShell script files can be edited to contain the appropriate variable (for example, client IDs and group IDs) and then saved to a secure network location. The user with rights to the Power BI resources, such as a BI manager or an IT administrator assigned the Power BI admin role, can run the PowerShell scripts as an administrator.

A top use case for the Power BI REST API is to synchronize the data refresh of Power BI datasets with the refresh process of data sources utilized by those datasets. For example, the refresh for certain production datasets in the Power BI service can be dynamically triggered to begin once the update process for a data source is completed, such as a nightly data warehouse extract-transform-load (ETL) or extract-load-transform (ELT) process or job. This synchronization ensures that Power BI reports and dashboards reflect the latest possible updates.

Additionally, the dynamic refreshes help to eliminate variances between Power BI reports and dashboards and any reporting tools which generate queries directly against the data source. Data refresh synchronization, along with incremental data refresh (expected in 2018), reduces one of the advantages of DirectQuery datasets relative to import mode datasets.

The refresh dataset API requires the group ID for the given app workspace and the dataset ID. These values can be obtained manually as per the Workspace and content IDs section earlier or via the Get Groups and Get datasets API operations, respectively. The following URL contains documentation on the Refresh dataset operation: http://bit.ly/2EpWLKL
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.108.119