Forum Discussion
Connecting PowerBI from Power Shell without prompting
I am trying to connect powerBI from powershell. I created a service account in azure AD and enabled service prinicipal in powerBI under admin portal. I am using the below commands.
$password = "xxxx" | ConvertTo-SecureString -asPlainText -Force
$username = "xxxx"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "xxxx"
But I am getting the below error
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 18:50:33 -
38e2e372-4bf9-4b59-bf89-d5a21444a81e] Request retry failed.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 18:50:33 -
38e2e372-4bf9-4b59-bf89-d5a21444a81e] Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: unauthorized_client
HTTP StatusCode 400
CorrelationId 38e2e372-4bf9-4b59-bf89-d5a21444a81e
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 18:50:33 -
38e2e372-4bf9-4b59-bf89-d5a21444a81e] Fetching a new AT failed. Is AAD down? False. Is there an AT in the cache that is
usable? False
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 18:50:33 -
38e2e372-4bf9-4b59-bf89-d5a21444a81e] Either the exception does not indicate a problem with AAD or the token cache does
not have an AT that is usable.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 18:50:33 -
38e2e372-4bf9-4b59-bf89-d5a21444a81e] Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: unauthorized_client
HTTP StatusCode 400
CorrelationId 38e2e372-4bf9-4b59-bf89-d5a21444a81e
I also tried running with application id. I got the below error.
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $password
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "1d0c38ac-c828-4447-ac9a-f638ea212db2"
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 19:08:46 -
76ce6781-9ddb-49d5-b5d7-e5f449dabea8] Request retry failed.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 19:08:46 -
76ce6781-9ddb-49d5-b5d7-e5f449dabea8] Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: invalid_request
HTTP StatusCode 400
CorrelationId 76ce6781-9ddb-49d5-b5d7-e5f449dabea8
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 19:08:46 -
76ce6781-9ddb-49d5-b5d7-e5f449dabea8] Fetching a new AT failed. Is AAD down? False. Is there an AT in the cache that is
usable? False
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 19:08:46 -
76ce6781-9ddb-49d5-b5d7-e5f449dabea8] Either the exception does not indicate a problem with AAD or the token cache does
not have an AT that is usable.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [05/12/2022 19:08:46 -
76ce6781-9ddb-49d5-b5d7-e5f449dabea8] Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: invalid_request
HTTP StatusCode 400
CorrelationId 76ce6781-9ddb-49d5-b5d7-e5f449dabea8
14 Replies
- AnonymousNot applicable
I just got this working the other day with the service principal approach. Are you authenticating using a client secret or certificate? If using certificate, I might be able to provide some assistance.
- kranthi_sunkaraRegular Visitor
Sorry I am new to PowerBI. I am not aware that I should use either of them. So, in order to use the client certificate, do I need to create it explicitly? For now, I am just trying with service prinicipal, tennent id and application id
- AnonymousNot applicable
If you're going to connect to the REST APIs using the service principal approach, when writing your scripts, you'll also need to supply the client secret or a certificate thumbprint. See the following article: Connect-PowerBIServiceAccount (MicrosoftPowerBIMgmt.Profile) | Microsoft Docs
- kranthi_sunkaraRegular Visitor
Thanks. Let me try with client secret or a certificate thumbprint