Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

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