Last active
July 1, 2023 12:47
-
-
Save jacqinthebox/430f9feef02a1c09f4b02cc89a98fe0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Login-PowerBI | |
$workspaces = Get-PowerBIWorkspace | |
$sourceServer = server01.database.windows.net | |
$sourceDatabase = database01.database.windows.net | |
$destinationServer = server02.database.windows.net | |
$destinationDatabase = database02.database.windows.net | |
foreach ($workspace in $workspaces) { | |
$workspace | |
$datasets = Get-PowerBIDataset -WorkspaceId $workspace.Id | |
foreach ($dataset in $datasets | Where-Object{$_.IsRefreshable -eq $true}) { | |
Write-Host "Start updating dataset " $dataset.Name " in workspace " $workspace.Name | |
Get-PowerBIDatasource -DatasetId $dataset.Id | |
# $urlTakeOver = "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($dataset.Id)/Default.TakeOver" | |
# Invoke-PowerBIRestMethod -Url $urlTakeOver -Method Get | |
$url = "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($dataset.Id)/Default.UpdateDatasources" | |
$body = '{ | |
"updateDetails": [ | |
{ | |
"datasourceSelector": { | |
"datasourceType": "Sql", | |
"connectionDetails": { | |
"server": "$sourceServer", | |
"database": "$sourceDatabase" | |
} | |
}, | |
"connectionDetails": { | |
"server": "$destinationServer", | |
"database": "$destinationDatabase" | |
} | |
} | |
] | |
}' | |
Invoke-PowerBIRestMethod -Url $url -Method Post -Body $body | |
Write-Host "Finished updating dataset " $dataset.Name " in workspace " $workspace.Name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment