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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
tobny76
Helper II
Helper II

Disable refreshes before release - RestAPI

Hi all!
I have done a powershell script for disable refeshes for selected datasets in an excel file.
I have only tested on my own dataset and it has been working well.
Now when I should run it on almost all datasets it says that I need to be the dataset owner to do this, see below.

tobny76_0-1757511997324.png

 

I'm admin on the capacity and has admin permissions on the workspaces as well.
Can I force this even if I'm not the owner of the dataset?

# Login to Power BI
#Login-PowerBIServiceAccount

$choice = Read-Host "Do you want to ENABLE or DISABLE the refresh for the datasets? (Type 'enable' or 'disable' or other for exit)"

# Validate input and set the body accordingly
# Define the body for disabling/enabling refresh
switch ($choice.ToLower()) {
    "enable"  { $body = "{ 'value': { 'enabled': true } }" }
    "disable" { $body = "{ 'value': { 'enabled': false } }" }
    default {
        Write-Host "Invalid choice. Please run the script again and type 'enable' or 'disable'."
        exit
    }
}

# Change this path to your location of the file when running.
$excelPath = "C:\Release25-37.xlsx"


# Read the Excel file
#$refreshTargets = Import-Excel -Path $excelPath -WorksheetName "RefreshTargets"
$refreshTargets = Import-Excel -Path $excelPath


# Show the user what will be updated
Write-Host "`nThe following datasets will be updated to $choice"
foreach ($target in $refreshTargets | Where-Object { $_.Include -eq "Y" }) {
    Write-Host "GroupId: $($target.GroupId) | Workspace $($target.GroupIdName) | DatasetId: $($target.DatasetId) | DatasetIdName: $($target.DatasetIdName)"
}

# Ask for confirmation
$confirm = Read-Host "`nDo you want to proceed with $choice of these datasets? ([y]=yes/ [n]=no)"
if ($confirm.ToLower() -ne "y") {
    Write-Host "Operation cancelled by user."
    exit
}

# Proceed with update
# Filter and loop through each row marked for inclusion
foreach ($target in $refreshTargets | Where-Object { $_.Include -eq "Y" }) {
    $groupId = $target.GroupId
    $datasetId = $target.DatasetId
    $url = "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshSchedule"
    Write-Host "INFO  - Updating refresh schedule for Group: $groupId, Dataset: $datasetId"
    Invoke-PowerBIRestMethod -Url $url -Method PATCH -Body $body
}


 

1 ACCEPTED SOLUTION
Thomaslleblanc
Super User
Super User

no you cannot, must own the model. A good best practice is to use a 'service account' to own the semantic models, and use that Entra Account to execute the refresh or disable

View solution in original post

1 REPLY 1
Thomaslleblanc
Super User
Super User

no you cannot, must own the model. A good best practice is to use a 'service account' to own the semantic models, and use that Entra Account to execute the refresh or disable

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.