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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Connect by Powershell

My Powershell script to connect to the Service is failing at the first hurdle:

 

This is how I'm trying to connect:

Import-Module MicrosoftPowerBIMgmt
Connect-PowerBIServiceAccount -Tenant xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -ServicePrincipal -Credential (Get-Credential)

This seems to match Example 3 from MIcrosoft's guidance:

https://docs.microsoft.com/en-us/powershell/module/microsoftpowerbimgmt.profile/connect-powerbiservi... 

 

But I get the following error message:

Connect-PowerBIServiceAccount : One or more errors occurred.
At C:\Temp\Scripts\PBIScript.ps1:9 char:1
+ Connect-PowerBIServiceAccount -Tenant xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBIServiceAccount

 

The account I'm trying to use to connect is covered by our MFA policy - so I am expecting to get an MFA prompt.

 

The script doesn't need to be automated, I'[m happy to receive a manual prompt for username, password and MFA.

 

 

 

7 REPLIES 7
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Have you installed "MicrosoftPowerBIMgmt" module?

 

Install-Module -Name MicrosoftPowerBIMgmt

 

Referencing: https://docs.microsoft.com/powershell/module/microsoftpowerbimgmt.profile/connect-powerbiserviceaccount?view=powerbi-ps#example-3 

 

And you can also see if these posts are helpful.

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

Can't connect to PowerBI service account 

 

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

 

Anonymous
Not applicable

Yes, I have installed the "MicrosoftPowerBIMgmt" module.

 

A present my script looks like this:

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

Connect-PowerBIServiceAccount

But I get the error below:

 

Connect-PowerBIServiceAccount : One or more errors occurred.
At C:\Temp\Scripts\PBIScript.ps1:15 char:1
+ Connect-PowerBIServiceAccount
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], Aggregat
eException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBIServiceAccount

 

 

 

Hi @Anonymous ,

 

This error will be thrown when the login fails. I tested and found that I could not connect using a MFA account. You need to disable the MFA for your account. Or you can use service principal and an application secret, like this

 

vkkfmsft_2-1629788516719.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

 

Anonymous
Not applicable

Disabling MFA on my account isn't an option. I have tried to connect using a service principal, but it still doesn't work:

 

My script:

 

#Import
Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

#Variables 
$AppId = "XXXX"
$TenantId = "XXXX"
$ClientSecret = "XXXX" 

#Create secure string & credential for application id and client secret
$PbiSecurePassword = ConvertTo-SecureString $ClientSecret -Force -AsPlainText
$PbiCredential = New-Object Management.Automation.PSCredential($AppId, $PbiSecurePassword)

#Connect to the Power BI service
Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId -Credential $PbiCredential

Disconnect-PowerBIServiceAccount

 

 

Error message:

 

 

Connect-PowerBIServiceAccount : One or more errors occurred.
At C:\Temp\Scripts\Script.ps1:26 char:1
+ Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBIServiceAccount

 

Hi @Anonymous ,

 

After you have successfully set up the service principal, please try the following script:

 

Import-Module MicrosoftPowerBIMgmt

Connect-PowerBIServiceAccount -Tenant xxxxx -ServicePrincipal -Credential (Get-Credential)

vkkfmsft_0-1630054845117.png

 

After enter, the following window will pop up, then enter your Application ID and client secret.

 

tempsnipafa.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

Anonymous
Not applicable

I have tried this, and once more received the same error message as per screenshot below. My expected result is to run the Connect-PowerBIServiceAccount command without any errors (at which point I'll proceed with the rest of my script).

ServicePrincipal1.PNG

 

ServicePrincipal2.PNG

Hi @Anonymous ,

 

Have you enabled the Power BI service admin settings? For an Azure AD app to be able to access the Power BI content and APIs, a Power BI admin needs to enable service principal access in the Power BI admin portal.

Add the security group you created in Azure AD, to the specific security group section in the Developer settings.

 

Embed Power BI content with service principal and an application secret 

 

If this error still persists, please use fiddler to trace details error message about that powershell request, or see if these document are helpful

https://stackoverflow.com/questions/57772073/programmatically-authenticate-into-aad-with-mfa-via-powershell 

 

 

Best Regards,
Winniz

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors