Forum Discussion
Powershell Update report credentials --Service Principle
lbendlin My bad, sorry.
Here's by POSH (lots of comments) but thanks to your prompt, I've noticed it was duplicating the gateway ID.
I was getting a body empty error but now I've removed the duplication on the GatewayID, I'm getting a 404 NOT FOUND ERROR which is progress. 🙂
#Workspace ID
$GroupId = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"
#DataSet
$DataSetId ="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyy"
$TakeOverUrl = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/datasets/$DatasetId/Default.TakeOver"
Invoke-PowerBIRestMethod -Url $TakeOverUrl -Method Post -Verbose
########## Above is working #####################
# Now get all the datasources for the dataSet & GatewayID
# Get all sources for dataset
$datasources = Get-PowerBIDatasource -WorkspaceId $GroupId -DatasetId $DataSetId
$datasources | Format-Table
$GatewayId =$datasources.GatewayId
## Hardcode datasourceID's for test --> need to loop ######
$GatewayDataSourceId1 = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa" # populate this from the GetGatewayDatasources.ps1
$GatewayDataSourceId2 = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbb" # populate this from the GetGatewayDatasources.ps1
$SetCreds = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/datasets/$DatasetId/Default.BindToGateway"
$Body = "{'gatewayObjectId': '$GatewayId', 'datasourceObjectIds': ['$GatewayDataSourceId1', '$GatewayDataSourceId2']}"
Write-Host $SetCreds
Write-Host $Body
Invoke-PowerBIRestMethod -Url $SetCreds -Method Patch -Body $Body -Verbose
Resolve-PowerBIError
What happens when you run that call from the sandbox?