Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Delete Azure Data Lake Storage connection on published report

I'm having troubles trying to remove a datasource within a published dataset. I'm using a Power Shell script along with PowerBI Rest API to do so. When I consume the Rest service it returns a 200 Http response but the datasource is never removed.

I don't know if I'm missing something or I'm just following the incorrect path.

By the way, I'm using a parameter to update the Azure Data Lake Storage Gen2 connection when promoting the report to another workspace.

I'm using this parameter as follows.

 

When I'm using PowerBI Actions along with some Power Shell scripts inside DevOps I'm able to update that parameter, but the problem is that after updating the parameter I see two Datasources sucessfully attached to the dataset but I will just be using one, when the refresh task comes in I'm having huge refresh times and some errors refered to overloaded memory.

 

Here is the power shell script I'm using to delete the unused datasource, but nothing happens with it.

 

#Login to PowerBI usgin a prompt
Login-PowerBI

# Script Variables
$adlHostOld = "generaldevelopment.dfs.core.windows.net"
$workspaceName = "Park IQ - Test"

#Get the required workspace
$workspace = Get-PowerBIWorkspace -Name $workspaceName

# Get all datasets in current workspace
if($workspace.Name -eq $workspaceName){
    Write-Host "Getting Datasets in Workspace $($workspace.Name) id: $($workspace.Id)"
    # Get all datasets in current workspace
    $wsDatasets = Invoke-PowerBIRestMethod -Url "groups/$($workspace.Id)/datasets" -Method Get | ConvertFrom-Json
    # Loop datasets of workspace
    foreach($dataset in $wsDatasets.value){
        $gateway = Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($dataset.id)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json
        Write-Host "Getting Datasources in Dataset $($dataset.name) with id: $($dataset.id)"
        # Takeover Datasets
        Invoke-PowerBIRestMethod -Url "groups/$($workspace.Id)/datasets/$($dataset.id)/Default.TakeOver" -Method Post
        foreach($datasource in $gateway.value){
	        if($datasource.datasourceType -eq "AzureDataLakeStorage" -and $datasource.connectionDetails.Contains($adlHostOld)) {
		        Write-Host "Found datasource $($datasource.datasourceType)"
                Write-Host "Datasource connection details: $($datasource.connectionDetails)"
                Write-Host "This datasource will be deleted! WARNING!"
                Write-Host "Datasource to delete details --> GatewayId: $($datasource.gatewayId); DataSourceId: $($datasource.id)"
                $result = Invoke-PowerBIRestMethod -Url "gateways/$($datasource.gatewayId)/datasources/$($datasource.id)" -Method DELETE
                Write-Host $result
	        }
        }
        #Get all datasources inside current dataset
        <#
        $dataSources = Invoke-PowerBIRestMethod -Url "datasets/$($dataset.id)/datasources" -Method Get | ConvertFrom-Json
        foreach($datasource in $dataSources.value){
            if($datasource.datasourceType -eq "AzureDataLakeStorage" -and $datasource.connectionDetails.server -eq $adlHostOld) {
                Write-Host "Found datasource $($datasource.datasourceType)"
                Write-Host "Datasource connection details: $($datasource.connectionDetails)"
                Write-Host "This datasource will be deleted! WARNING!"
                Write-Host "Datasource to delete details --> GatewayId: $($datasource.gatewayId); DataSourceId: $($datasource.datasourceId)"
                $result = Invoke-PowerBIRestMethod -Url "gateways/$($datasource.gatewayId)/datasources/$($datasource.datasourceId)" -Method DELETE
                Write-Host $result
            }
        }
        #>
    }
}

 

 

I will appreciate if someone can help me address this matter.

 

Regards

1 Reply

  • v-deddai1-msft's avatar
    v-deddai1-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    I am not very good at using powershell, I suggest you also open a post on powershell forumn. If you have Pro account I suggest you  try to open a support ticket. If you have a Pro account it is free. Go to https://support.powerbi.com. Scroll down and click "CREATE SUPPORT TICKET".

     

    Best Regards,

    Dedmon Dai