Last active
July 26, 2022 04:24
-
-
Save samaguire/8c8f490f7b5fecec9f9d7fd44e93ec6a to your computer and use it in GitHub Desktop.
A quick PowerShell 7 script to turn on compute for Power BI Dataflows
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
#Requires -Modules @{ ModuleName="MicrosoftPowerBIMgmt"; ModuleVersion="1.2.1026" } | |
Connect-PowerBIServiceAccount | |
$workspaces = @( | |
"c9d2e54d-e2ae-4e40-909c-716baf07bbeb", | |
"ca79234f-094f-49c2-9519-453b562031a3", | |
"5e975ca7-6c75-419f-b73b-0393708b936d" | |
) | |
$workspaces | ForEach-Object -ThrottleLimit 5 -Parallel { | |
$baseUrl = "https://api.powerbi.com/v1.0/myorg" | |
$groupId = $_ | |
$url = [string]::Format("{0}/groups/{1}/dataflows", $baseUrl, $groupId) | |
$dataflows = ((Invoke-PowerBIRestMethod -Url $url -Method Get) | ConvertFrom-Json).value.objectId | |
$dataflows | Foreach-Object -ThrottleLimit 5 -Parallel { | |
$bodyJson = '{"computeEngineBehavior": "computeOn"}' | |
$dataflowId = $_ | |
$url = [string]::Format("{0}/groups/{1}/dataflows/{2}", $using:baseUrl, $using:groupId, $dataflowId) | |
Invoke-PowerBIRestMethod -Url $url -Method Patch -Body $bodyJson -ContentType "application/json" -ErrorAction SilentlyContinue | |
if($Error[0]) { | |
[pscustomobject]@{"Workspace ID" = $using:groupId; "Dataflow ID" = $dataflowId; "Error Message" = $Error[0].ToString()} | |
} else { | |
[pscustomobject]@{"Workspace ID" = $using:groupId; "Dataflow ID" = $dataflowId} | |
} | |
} | |
} | |
Read-Host "`r`nPress enter to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment