Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

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:

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

 

 

  • Hi Anonymous 

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

     

2 Replies