Forum Discussion

dom99's avatar
dom99
Advocate V
6 years ago
Solved

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 - c...
  • Jayendran's avatar
    6 years ago

    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