Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Refresh a Power BI Dataset with PowerShell

How to refresh a Power BI Dataset with PowerShell.

 

could you please help me the step by step details for the same.

2 Replies

  • # Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
    function GetAuthToken
    {
        if(-not (Get-Module AzureRm.Profile)) {
            Import-Module AzureRm.Profile
        }
        $clientId = "*****"
        $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
    }
    
    # Get the auth token from AAD
    $token = GetAuthToken
    
    # Building Rest API header with authorization token
    $authHeader = @{
        'Content-Type'='application/json'
        'Authorization'=$token.CreateAuthorizationHeader()
    }
    
    # Refresh the dataset
    
    $groupsPath = "*****"
    $datasetID  = "*****"
    
    $MailFailureNotify = @{"notifyOption"="MailOnFailure"}
    $uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
    Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST -Body $MailFailureNotify –Verbose