Forum Discussion

PowerBI-ELM's avatar
PowerBI-ELM
Helper I
4 years ago

Cannot login with Powershell

Hello,

 

I am trying to login to PowerBI using Power Shell.   If I just use Connect-PowerBIServiceAccount by itself, it pops open the login dialog and then carries on properly.  


But if I try to embed the password, it gives me an error:

 

Code:

$password = "thepassword" | ConvertTo-SecureString -asPlainText -Force
$username = "[email protected]"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential

 

Resolve-PowerBIError -Last

      Message : Error Acquiring Token:
      AADSTS50126: Error validating credentials due to invalid username or password.

 

(The less helpful message given by the login attempt is shown below, so to make the question easier to read.)

 

I have been Googling around and trying random suggestions, but I cannot seem to figure out what is preventing the error.  I have, of course, convinced myself that the username and password are actually entered correctly.

 

Thanks

Stephen

 


The first part of the message the command gives is as follows:

Connect-PowerBIServiceAccount : One or more errors occurred.
At C:\....\PowerShell\Clear.ps1:21 char:2
+ Connect-PowerBIServiceAccount -Credential $credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], Aggr
egateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBIServiceAccount

WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19044.0 [06/20/2022 19:44:14 - f3fe14c0-a2f2-486a-82b6-f0ab1d92bd9c] Request
retry failed.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19044.0 [06/20/2022 19:44:14 - f3fe14c0-a2f2-486a-82b6-f0ab1d92bd9c] Excepti
on type: Microsoft.Identity.Client.MsalUiRequiredException
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId f3fe14c0-a2f2-486a-82b6-f0ab1d92bd9c

5 Replies

    • PowerBI-ELM's avatar
      PowerBI-ELM
      Helper I

      I should have the most recent API as just set it up recently.  Also, just in case I tried an update.

      I do not have MFA installed.

      So still stuck ...

      • GilbertQ's avatar
        GilbertQ
        Super User

        Hi PowerBI-ELM 

         

        Yeah the only other thing would be to chat to your Azure/Network Admin to make sure that they allow the account to log in via the PowerShell commands?