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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors