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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
dom99
Advocate V
Advocate V

Set Service Principal s Dataset Owner

Hi,

 

I wonder if someone can help me. I need to set an existing dataset to be owned by a service principal but cant seem to manage it.

 

the two options I can see are:

 

1. Manually set it - cant do this because setting manually assigns the dataset ownership as the logged in user, but you cant log in to the service as a service principal

 

2. use the powershell API - same problem here, there doesnt seem to be an option to set who owns it, it just picks up the logged in user and I dont know how to log in via the API as a service principal. Found a take over script example here https://github.com/Azure-Samples/powerbi-powershell/blob/master/takeover-dataset.ps1

 

Does anyone know how I can do this?

 

Thanks

1 ACCEPTED SOLUTION
Jayendran
Solution Sage
Solution Sage

Hi @dom99 ,

 

Using powershell it is possible

 

I already created the entier script and published here

https://gallery.technet.microsoft.com/AzureDevOps-CICD-for-fefd58b8

 

The powershell scripts looks like

 

$applicationId = "" 
$clientsec = "" | ConvertTo-SecureString -AsPlainText -Force # 
 
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "" 
  
 
$workspacename="PowerBI_CICD_PROD" 
$datasetname="AdventureReports" 
##Getworksapce 
 
$workspace =Get-PowerBIWorkspace -Name $workspacename 
 
# GetDataSets 
$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json 
 
 
# Get DataSet 
$datasets = $DatasetResponse.value 
 
     foreach($dataset in $datasets){ 
                if($dataset.name -eq $datasetname){ 
                $datasetid= $dataset.id; 
                break; 
                } 
 
            } 
 
## Take Over DataSet 
 
Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.TakeOver" -Method Post 

 

View solution in original post

6 REPLIES 6
tackytechtom
Super User
Super User

Hiya!

 

Although I am pretty late to this party here, I still wanted to distribute two blog posts that are very much related to this topic. So, in case someone finds him/herself in the situation where a service principal needs to own the power bi dataset, I hope you find any of the following helpful.

 

Blog Post A: 

https://www.tackytech.blog/how-to-make-a-service-principal-the-owner-of-a-power-bi-dataset/

A walkthrough on how to take over a dataset by a service principal via an Azure DevOps pipeline. Likewise to the accepted answer in this thread here, the core is also a Powershell script that can be used outside an Azure DevOps pipeline as well.

 

Blog Post B: 

https://www.tackytech.blog/how-to-retrieve-oauth2-access-tokens-for-data-sources-via-data-factory-to...

An ETL flow in Azure Data Factory where the data factory is responsible for updating the oauth2 token for all data sources in the power bi dataset prior to kickstarting the dataset refresh (via managed identity). Here, a prerequesite is that the dataset is owned by a service principal.

 

Once again, I hope this is helping! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Jayendran
Solution Sage
Solution Sage

Hi @dom99 ,

 

Using powershell it is possible

 

I already created the entier script and published here

https://gallery.technet.microsoft.com/AzureDevOps-CICD-for-fefd58b8

 

The powershell scripts looks like

 

$applicationId = "" 
$clientsec = "" | ConvertTo-SecureString -AsPlainText -Force # 
 
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "" 
  
 
$workspacename="PowerBI_CICD_PROD" 
$datasetname="AdventureReports" 
##Getworksapce 
 
$workspace =Get-PowerBIWorkspace -Name $workspacename 
 
# GetDataSets 
$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json 
 
 
# Get DataSet 
$datasets = $DatasetResponse.value 
 
     foreach($dataset in $datasets){ 
                if($dataset.name -eq $datasetname){ 
                $datasetid= $dataset.id; 
                break; 
                } 
 
            } 
 
## Take Over DataSet 
 
Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.TakeOver" -Method Post 

 

Hi @Jayendran 

 

I've tried your script but unfortunatly the method below fails.

 

Invoke-PowerBIRestMethod

 

 I successfully log in as the service principal and assign the values as required, the script works up until the very end.

 

The error message is:

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:3 char:1
+ Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($da ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIR
estMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

 

Can you help with finding out why its not working? I found your powershell scripts you'd uploaded, very handy to have thank you.

Hi @dom99 ,

 

  • Make sure that SPN have admin access to your Workspace.
  • Make sure the workspace id ,datasetid are properly passing to the script 

 

After you got the error run the below script

 

Resolve-PowerBIError

Which will gives you the exact error

 

Hi @Jayendran 

 

I read the documentation and turns out the -Body parameter (sometimes called the content) is now required for POST operations.

 

so the invoke method looks like:

 

Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.TakeOver" -Method Post -Body ""

 

thanks for your help 🙂

@Jayendran Hi, thanks for the response.

 

Great thank you thats exactly what I needed. I will try it out shortly 🙂

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors