Last active
October 24, 2022 16:38
-
-
Save win2000b/f56b87c537e82ee9ec8f173914937d70 to your computer and use it in GitHub Desktop.
Take OwnerShip of PowerBI Dataset, Change Datasource and then output result
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
# Connect to PowerBI Service In PowerShell | |
Connect-PowerBIServiceAccount | |
# Import the Data File for all the PowerBI Datasets you want to change. | |
$src = Import-CSV "c:\temp\DataImport.csv" | |
foreach ($line in $src) { | |
$GetURL = "https://api.powerbi.com/v1.0/myorg/groups/$($line.WorkSpaceID)/datasets/$($line.DatasetID)/datasources" | |
$TakeOwnURL = "https://api.powerbi.com/v1.0/myorg/groups/$($line.WorkSpaceID)/datasets/$($line.DatasetID)/Default.TakeOver" | |
$SubmitURL = "https://api.powerbi.com/v1.0/myorg/groups/$($line.WorkSpaceID)/datasets/$($line.DatasetID)/Default.UpdateDatasources" | |
$obj = [PSCustomObject]@{"updateDetails" = @(@{"datasourceSelector" = @{"datasourceType" = "AnalysisServices"; "connectionDetails" = @{"server" = $($line.serverOLD); "database" = $($line.databaseold)}}; "connectionDetails" = @{"server" = $($line.serverNEW); "database" = $($line.databaseNEW)}})} | |
$JSON = $obj | ConvertTo-JSON -Depth 10 | |
# Comment out the lines below once testing complete | |
Write-Host $JSON | |
Write-Host "Submit URL to be Used: $SubmitURL" | |
Write-Host "Takeown URL to be Used: $TakeOwnURL" | |
# Uncomment out the lines below when ready to implement. | |
# Invoke-PowerBIRestMethod -Url $TakeOwnURL -Method Post | |
# Invoke-PowerBIRestMethod -Url $SubmitURL -Method POST -Body $JSON | |
# Invoke-PowerBIRestMethod -Url $GetURL -Method GET | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment