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
Anonymous
Not applicable

Powershell unable to Connect to PowerBI service using credentials

Hello, can anyone offer any advise regarding this issue:

 

Login-PowerBIServiceAccount : One or more errors occurred.
At line:1 char:1
+ Login-PowerBIServiceAccount -Credential $mycred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], AggregateException
+ 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.19043.0 [04/28/2022 02:49:03 - cc9be2ae-955b-41b5-9543-2b81cfbae482] Request retry failed.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [04/28/2022 02:49:03 - cc9be2ae-955b-41b5-9543-2b81cfbae482] Exception type: Micro
soft.Identity.Client.MsalUiRequiredException
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId cc9be2ae-955b-41b5-9543-2b81cfbae482

WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19043.0 [04/28/2022 02:49:03 - cc9be2ae-955b-41b5-9543-2b81cfbae482] Exception type: Micro
soft.Identity.Client.MsalUiRequiredException
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId cc9be2ae-955b-41b5-9543-2b81cfbae482

at Microsoft.Identity.Client.OAuth2.OAuth2Client.ThrowServerException(HttpResponse response, RequestContext requestContext)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T](HttpResponse response, RequestContext requestContext)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.<ExecuteRequestAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.<GetTokenAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.OAuth2.TokenClient.<SendHttpAndClearTelemetryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Identity.Client.OAuth2.TokenClient.<SendHttpAndClearTelemetryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.OAuth2.TokenClient.<SendTokenRequestAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.Internal.Requests.RequestBase.<SendTokenRequestAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.Internal.Requests.UsernamePasswordRequest.<ExecuteAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.Internal.Requests.RequestBase.<RunAsync>d__13.MoveNext()

 

I am constantly getting this error when I try connecting to PowerBI-Service using credentials that I have defined in PowerShell:

 

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

# Define Credentials
$userName = 'abc@123.com'
$password = 'example'
$securePwd = ConvertTo-SecureString $password -AsPlainText -Force

# Create the credential object
[pscredential]$mycred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $securePwd

# Code here

# Login to PowerBI using account with service admin rights
Connect-PowerBIServiceAccount -Credential $mycred

 

Thank You!

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please refer to the past solutions. The same error was encountered in this post, the reason is that some Power BI modules are not installed.

Solved: Re: PowerShell Login to Power BI - Write Error

 

Please install these modules.

MicrosoftPowerBIMgmt.Admin
MicrosoftPowerBIMgmt.Capacities
MicrosoftPowerBIMgmt.Data
MicrosoftPowerBIMgmt.Profile
MicrosoftPowerBIMgmt.Reports
MicrosoftPowerBIMgmt.Workspaces

 

Best Regards,
Community Support Team Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!

View solution in original post

4 REPLIES 4
glilly1
New Member

That doesn't explain why I was able to access and run the REST API's just fine for over 6 months with no issues... and suddenly, now I get the same above error when It ry to run my PS Scripts. I was using the 'New-Object -TypeName System.Management.Automation.PSCredential -argumentlist 'Username', 'Password' and passed the credentual to 'Connect-PowerBIServiceAccoutnt' just fine as I mentioned... then it just stopped working.

 

v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please refer to the past solutions. The same error was encountered in this post, the reason is that some Power BI modules are not installed.

Solved: Re: PowerShell Login to Power BI - Write Error

 

Please install these modules.

MicrosoftPowerBIMgmt.Admin
MicrosoftPowerBIMgmt.Capacities
MicrosoftPowerBIMgmt.Data
MicrosoftPowerBIMgmt.Profile
MicrosoftPowerBIMgmt.Reports
MicrosoftPowerBIMgmt.Workspaces

 

Best Regards,
Community Support Team Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!

Anonymous
Not applicable

Hi, Is there a way to solve the issue without having an application within Azure AD

Hi @Anonymous ,

 

When you use the REST API, this is a necessary prerequisite.

 

To use the Power BI REST APIs, you need to register an Azure Active Directory (Azure AD) application in Azure. The Azure AD app establishes permissions for Power BI REST resources, and allows access to the Power BI REST APIs. To learn how to register an app, see Register an Azure AD application to use with Power BI.

Power BI REST APIs for embedded analytics and automation

 

Best Regards,
Community Support Team Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!

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