Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PowerBI-ELM
Helper I
Helper I

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 = "user@domain.com"
$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 5
GilbertQ
Super User
Super User

Hi @PowerBI-ELM 

 

Do you have MFA enabled on your account?

 

Looking at your code it is what I have and it certainly works for me.

 

Also just to confirm you have got the latest version of the PowerBI PowerShell Modules installed?

Power BI Cmdlets reference | Microsoft Docs





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

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 ...

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?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

my login (email) is a powerbi admin and a global admin.  Is there anything else?

Hi @PowerBI-ELM 

 

Ahh wait can you make sure where you are running PowerShell that you have TLS 1.2 enabled?

 

If not put this at the start of the PowerShell Script

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.