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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Connect-PowerBIServiceAccount getting error in power shell script

I need to connect POWER BI account without prompting and password would be secure not in script file .

Below is the powershell script :

 

Clear-Host
$PSScriptRoot= "D:\powershell"
$pathFile = $PSScriptRoot + "\logs\"
$pwdpath = $PSScriptRoot + "\pwd\"
$pwdfile = $pwdpath + "creds.xml"

<# Get password from file, if file exists. Else, create folder and export params after prompted to user. #>

if(Get-Module -Name MicrosoftPowerBIMgmt -ListAvailable){
#Update-Module MicrosoftPowerBIMgmt -Force
}else{
Install-Module MicrosoftPowerBIMgmt -Scope CurrentUser -Force
}


if([System.IO.File]::Exists($pwdfile)){
$mycreds = Import-CliXml -Path $pwdfile
} else {
if(!([System.IO.File]::Exists($pwdpath))){
New-Item -Path $PSScriptRoot -Name "pwd" -ItemType Directory
}
Get-Credential | Export-CliXml -Path $pwdfile
$mycreds = Import-CliXml -Path $pwdfile
}
Connect-PowerBIServiceAccount -Credential $mycreds

 

It throws an error :

Connect-PowerBIServiceAccount : One or more errors occurred.
At line:25 char:1
+ Connect-PowerBIServiceAccount -Credential $mycreds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [
Connect-PowerBIServiceAccount], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBI
ServiceAccount

WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.18363.0 [07/13/2021 05:00:52 - c63c9973-
daa8-46e8-be4a-3d848c33c03c] Request retry failed.
WARNING: (False) MSAL 4.25.0.0 MSAL.Desktop Microsoft Windows NT 10.0.18363.0 [07/13/2021 05:00:52 - c63c9973-
daa8-46e8-be4a-3d848c33c03c] Exception type: Microsoft.Identity.Client.MsalClientException
, ErrorCode: user_realm_discovery_failed

at Microsoft.Identity.Client.WsTrust.CommonNonInteractiveHandler.<QueryUserRealmDataAsync>d__4.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.<FetchAssertionFromWsTrustAsync>d__4
.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.HandleNonSuccessAndDebuggerNotificatio

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous 

I cannot restore your issue .But I found a similar issue in Forums for you ,maybe you can refer to it .

https://community.powerbi.com/t5/Service/PowerShell-Login-to-Power-BI-Write-Error/m-p/1094922

 

Best Regards

Community Support Team _ Ailsa Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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