Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I have been trying creating PowerBi data source via Powershell however it's not working.
My code is,
Login-PowerBIServiceAccount
$gatewayId = "5***********************************************"
$URL = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId"
$Body = @{
dataSourceType = "Web"
datasourceName = "Junk"
connectionDetails = "{`"path`":`"https://junk.junk.com.au/api/views/S%20Reporting%20Collection/Process%20by%20Location`"}"
credentialDetails = @{
credentialType = "Basic"
credentials = "{`"credentialData`":[{`"name`":`"username`", `"value`":`"S*****************`"},{`"name`":`"password`", `"value`":`"P*******`"}]}"
encryptedConnection = "None"
encryptionAlgorithm = "None"
privacyLevel = "Organizational"
}
} | ConvertTo-Json
#$Body
$response = Invoke-PowerBIRestMethod -Url $URL -Method post -Body $Body -Verbose
Error:
Invoke-PowerBIRestMethod : One or more errors occurred.
At line:19 char:13
+ $response = Invoke-PowerBIRestMethod -Url $URL -Method post -Body $Bo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
VERBOSE: Request Uri: https://api.powerbi.com/v1.0/myorg/gateways/5************************************
VERBOSE: Status Code: NotFound (404)
My code is based on https://community.powerbi.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/td-p/5...
My question is, do I need to have PowerBi admin role in Microsoft 365 to be able to create data sources ? I wouldn't have thought so. I am administrator on the PowerBi gateway where trying to create data source. Thought that would have been sufficient.
According to https://www.youtube.com/watch?v=SQ7ufcRayYY&list=PLIa2Rws8_X8hTpasShIpNIQsobxRCGlrw&index=2&t=0s, it seems PowerBi admin role is needed to create PowerBi data sources through Powershell.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.