Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello experts,
I'm fairly new to working with API. I've been trying this out without success and in need of assistance to see what went wrong and how could I fix it.
Powershell with Service Principle account is being used to perform this task, I believe all needed permission has been granted via Azure Active Directory.
Process
Script of the PowerShell
$Workspacename = xxx
$Datasetname = xxx
$ClientID = xxx
$ClientSecret = xxx
$TenantID = xxx
$applicationId = $ClientID # Need to pass the clientid from devops variable
$clientsec = $ClientSecret | ConvertTo-SecureString -AsPlainText -Force # Need to pass from devops secret variable
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec
#Install-Module -Name MicrosoftPowerBIMgmt.Profile -Verbose -Scope CurrentUser -Force
#Install-Module -Name MicrosoftPowerBIMgmt.Workspaces -Verbose -Scope CurrentUser -Force
$Connect = Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -Environment Public -Tenant $TenantID
$workspace = Get-PowerBIWorkspace -Name $Workspacename
$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json
$datasets = $DatasetResponse.value
foreach($dataset in $datasets){
if($dataset.name -eq $Datasetname){
$datasetid= $dataset.id;
break;
}
}
Invoke-PowerBIRestMethod -URL "groups/$($Workspace.id)/datasets/$($Dataset.id)/Default.TakeOver" -Method Post
$DisableScriptJson = @{
value= @{
enabled= "false"
}
} | ConvertTo-Json
Invoke-PowerBIRestMethod -URL "groups/$($Workspace.id)/datasets/$($Dataset.id)/refreshSchedule" -METHOD Patch -Body $DisableScriptJson | ConvertFrom-Json
Error
Invoke-PowerBIRestMethod : One or more errors occurred.
At line:42 char:2
+ Invoke-PowerBIRestMethod -URL "groups/$($Workspace.id)/datasets/$($D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
Any help is appreciated, let me know if further information is needed
Hi @zuheirashraf17 ,
Do you have permissions for read and write?
My understanding is that in order for the API to work it actually has to write permissions with the dataset.
Before you run this command, make sure you log in using Connect-PowerBIServiceAccount.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello Liang/@V-lianl-msft , appreciate your reply.
As for the permission, I believe this should be enough right?
As for Connect-PowerBIServiceAccount, it was able to connect just fine, please see my script. And the service account has admin access to the workspace too. In fact it was able to take over the dataset, but fail when trying to update/disable the refresh schedule.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
4 | |
4 | |
3 | |
3 | |
3 |