Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Invoke dataset refresh in PowerBI service from Powershell Azure

Hello,

I have the below script that I run from my Azure Automation account runbook. I am trying to refresh a dataset in PowerBI from the Powershell script placed in Azure portal.

 

$TenantId = "4*******-****-****-****-************"
$GroupId = "4*******-****-****-****-************"
$DatasetId = "1*******-****-****-****-************"
$Creds = Get-AutomationPSCredential -Name 'PowerBI_user'

$ErrorActionPreference = "Continue"

Connect-PowerBIServiceAccount -Tenant $TenantId -ServicePrincipal -Credential $Creds

$headers = Get-PowerBIAccessToken

$uri = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/datasets/$DatasetId/refreshes"
 
But I get the below error:
 
 
(False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 6.2.9200.0 [06/07/2022 08:32:22 - ***********] Request retry failed.
(False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 6.2.9200.0 [06/07/2022 08:32:22 - ************] Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: unauthorized_client
HTTP StatusCode 400
CorrelationId ***********
(False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 6.2.9200.0 [06/07/2022 08:32:22 - ***********] Fetching a new AT failed. Is AAD down? False. Is there an AT in the cache that is usable? False
(False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 6.2.9200.0 [06/07/2022 08:32:22 - ***********] Either the exception does not indicate a problem with AAD or the token cache does not have an AT that is usable. 
(False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 6.2.9200.0 [06/07/2022 08:32:22 - ***********] Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: unauthorized_client
HTTP StatusCode 400
CorrelationId **********

.
.
.
.
.
Login first with Login-PowerBIServiceAccount
The remote server returned an error: (403) Forbidden.

This is a Pro account and dont have enough permissions for my user to see the setup or anything.

 

Appreciate if someone could point me in the right direction to fix this issue.

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous,

    It seems like you haven't signed in to your account before invoking cmdlet scripts. As the document mentioned, you need to log in to power bi service to provide the credentials for the following operations.

    Power BI Cmdlets reference | Microsoft Docs

    Regards,

    Xiaoxin Sheng

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

    It seems like you haven't signed in to your account before invoking cmdlet scripts. As the document mentioned, you need to log in to power bi service to provide the credentials for the following operations.

    Power BI Cmdlets reference | Microsoft Docs

    Regards,

    Xiaoxin Sheng