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.

Connect-PowerBIServiceAccount without prompting to pick an account

I am trying to connect PowerBI by passing crediting to automate the PowerShell script for extraction PBIX templates across the workspaces at organization level. This below script is not working.

Script:

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

$password = "mypassword" | ConvertTo-SecureString -asPlainText -Force
$username = "myemail"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Connect-PowerBIServiceAccount -Credential $credential

 

Errors:

Connect-PowerBIServiceAccount : Failed to get ADAL token: Unhandled Exception: System.AggregateException: One or more
errors occurred. ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:
accessing_ws_metadata_exchange_failed: Accessing WS metadata exchange failed --->
System.Net.Http.HttpRequestException: Response status code does not indicate success: 406 (NotAcceptable). --->
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: : Unknown error --- End of inner exception stack
trace --- --- End of inner exception stack trace --- at

Status: New
Comments
v-chuncz-msft
Community Support
VivekKumarSingh
New Member
Since PowerBI now has enabled the service principal, you don't need to worry about the username and password.
Using the Service Principal you can now able to log in without popup as well as username, password
 $applicationId = "xxxxxxxx";
$securePassword = "xxxxxx" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "xxxx"
Hanuma_AB
Frequent Visitor

Hi All,

 

Please let me know if there is any way to connect with Power BI Service "Connect-PowerBIServiceAccount" without prompting to pick an account

 

 

@Anonymous  Did you find any solution for it?

 

@VivekKumarSingh  Yes, you are right but ServicePrincipal it's own limitations.

  • Exporting a paginated report that has a Power BI dataset as its data source, is not supported for service principals.

 

Thanks

ashwin21
New Member

Made some changes to your script. This script works fine.

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

 

$password = 'mypassword' | ConvertTo-SecureString -asPlainText -Force
$username = 'myemail'
$credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $password


Connect-PowerBIServiceAccount -Credential $credential

Anonymous
Not applicable

Still getting an issue with the above script : 

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

try { 
Write-Output "New Login :" 
$User = "snafu_cred@snafu.com"
$PWord = ConvertTo-SecureString -String "ADD_SNAFU_PASS_HERE" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
Connect-PowerBIServiceAccount -Credential $Credential

Write-Output "New Login worked - disconnecting:" 
Disconnect-PowerBIServiceAccount
}
catch 
{
Write-Output "new login ran into an issue: $($PSItem.ToString())"
}


Gives the following error : 

Exception type: Microsoft.Identity.Client.MsalClientException, ErrorCode: parsing_wstrust_response_failed
---> Inner Exception Details
Exception type: Microsoft.Identity.Client.MsalServiceException
, ErrorCode: federated_service_returned_error
HTTP StatusCode 500

 How do we get past the MsalServiceException?

millwardt
Frequent Visitor

I'm having the same issue as above and getting the following errors - any ideas?

 

WARNING: (False) MSAL 4.27.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19042.0 [12/21/2022 16:50:22 - ] Request retry failed.
WARNING: (False) MSAL 4.27.0.0 MSAL.Desktop Microsoft Windows NT 10.0.19042.0 [12/21/2022 16:50:22 - ] Exception type: Microsoft.Identity.Client.MsalUiRequiredExceptio
n
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId 5ae37f2c-d0bb-490a-8c5c-1093d2fba5bc

pvuppala
Advocate II

If you're still dealing with this issue simply change

Login-PowerBIServiceAccount

to 

Connect-PowerBIServiceAccount

 

That worked for me this morning when I had similar issues.

Connect-PowerBIServiceAccount: 
Line |
   8 |  Login-PowerBIServiceAccount -Credential $Credential
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Error Acquiring Token:
AADSTS50126: Error validating credentials due to invalid username or password.
Trace ID: a25196c7-d3ac-4622-9118-d3ea9ff42401
Correlation ID: f6045c06-a30c-4042-aed9-c1eb227d1160
Timestamp: 2023-02-08 14:36:49Z)
WARNING: (False) MSAL 4.27.0.0 MSAL.NetCore Microsoft Windows 10.0.19044 [02/08/2023 14:36:49 - ] Request retry failed.
WARNING: (False) MSAL 4.27.0.0 MSAL.NetCore Microsoft Windows 10.0.19044 [02/08/2023 14:36:49 - ] Exception type: Microsoft.Identity.Client.MsalUiRequiredException  
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId f6045c06-a30c-4042-aed9-c1eb227d1160

WARNING: (False) MSAL 4.27.0.0 MSAL.NetCore Microsoft Windows 10.0.19044 [02/08/2023 14:36:49 - ] Exception type: Microsoft.Identity.Client.MsalUiRequiredException  
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId f6045c06-a30c-4042-aed9-c1eb227d1160

   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[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders)