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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Failed to automate the PowerShell script using service principal

Hello All,

 

Daily I want to automate the Powershell script for extracting Power BI tiles in all Dashboards using service principal. After running i am getting the below error. Can anyone please help me to run it.

PowerShell script i am using to extract Power BI tiles

$AppId = "Application ID"
$TenantId = "Tenant ID"
$ClientSecret = "Application password"

#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

$Dashboards = Get-PowerBIDashboard -scope Organization
$Tiles =
ForEach ($Dashboard in $Dashboards)
{
Write-Host $Dashboard.Name
ForEach ($Tile in (Get-PowerBITile -DashboardId $Dashboard.Id))
{
[pscustomobject]@{
DashboardID = $Dashboard.Id
DashboardName = $Dashboard.Name
ReportID=$tile.ReportId
}
}
}
$Tiles

 

Error message:

Ynr0225_0-1699610482653.png

To know the error details i am running the command (Resolve-PowerBIError) i got the below error:

Ynr0225_1-1699610755879.png

 

 

1 ACCEPTED SOLUTION
aj1973
Community Champion
Community Champion

Hi @Anonymous 

Most likely you are missing the -Scope Organization to access to all dashboards as Admin.

aj1973_0-1699739774351.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

View solution in original post

2 REPLIES 2
aj1973
Community Champion
Community Champion

Hi @Anonymous 

Most likely you are missing the -Scope Organization to access to all dashboards as Admin.

aj1973_0-1699739774351.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

ibarrau
Super User
Super User

Hi. There are different steps we can validate for this. I think most of them are explained in the replies of this recent post: https://community.fabric.microsoft.com/t5/Service/Recieving-403-Forbidden-when-Accessing-Dataset-via...

The only difference with your scenario is that the permissions involved are related to dashboards. Like: "Dashboard.ReadWrite.All and Dashboard.Read.All"

I hope that helps, if you can doubts please feel free to ask again and we can discuss reply by reply of the other post.


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

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.