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
MawashiKid2
Helper I
Helper I

PowerShell Login with Connect-PowerBIServiceAccount +ServicePrincipal error

Hi,

I am currently testing PowerShell scripts in combination with Power BI REST API which I intend to use in automation scenarios.

At this stage, all tests were successfully completed manually through Windows PowerShell console. 

The login option I used was Connect-PowerBIServiceAccount.

So to make a long story short, running   

 

 

 

Connect-PowerBIServiceAccount

 

 

 

will generate a prompt asking for user to login. After entering my credentials, script then runs perfectly, executing all defined code blocks, returning expected data results. Still that's not quite sufficient for automation as I need to find a way to remove prompt process. One suggestion was to use Service Principal

 

Now if I try to run the same Connect-PowerBIServiceAccount method with Service Principal, the following authentication block seems to run fine

 

 

 

Connect-PowerBIServiceAccount -ServicePrincipal -CertificateThumbprint XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -ApplicationId XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

 

 

 though it just stalls returning a 403 forbidden status code whenever I try to run any subsequent methods. So something's obviously broken in the authentication process and I don't believe it's strictly relatated to PowerShell. 
Any tested and  working POC on how to cope with this would be deeply appreciated.

Thank you 

  


 

1 ACCEPTED SOLUTION
MawashiKid2
Helper I
Helper I

Forget about my message. I found the solution. Everything is now running fully as expected😊🌟🌟🌟

View solution in original post

4 REPLIES 4
MawashiKid2
Helper I
Helper I

Forget about my message. I found the solution. Everything is now running fully as expected😊🌟🌟🌟

Anonymous
Not applicable

What was the solution @MawashiKid2 ?

The solution is to use an SPN (Register an app to embed Power BI content in a Power BI embedded analytics application - Power BI | ...). Once you have an SPN your code will change to:


#replace bold items with your values
$applicationId = "<guid>";
$securePassword = "<password>" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "<tenantid-guid>"

Hi,

 

I am doing some automation using PowerShell script with Power BI REST API. And, I came across your post. 

Could you share the solution to overcome  403 forbidden status for subsequent call?

 

Thanks!

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.