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.
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
3 | |
1 | |
1 | |
1 |
User | Count |
---|---|
25 | |
3 | |
2 | |
2 | |
2 |