Forum Discussion
Getting error using Power Shell Script to update data sources.
You are facing an UnknownError while updating the data source credentials in Power BI using a PowerShell script within an Azure DevOps CI/CD pipeline. The issue is likely related to service principal permissions, incorrect dataset references, or an invalid JSON request body structure. First, ensure the service principal has the necessary API permissions in Azure AD, such as Dataset.ReadWrite.All, Tenant.ReadWrite.All, and Workspace.ReadWrite.All, and that Admin consent has been granted. Additionally, in the Power BI Admin Portal, enable service principal access under Tenant Settings and confirm that the service principal is assigned as a Member or Admin in the target workspace.
Another common issue is incorrect dataset and workspace references in your script. You need to correctly assign $datasetId = $dataset1.Id instead of using an undefined variable $dataset. Also, verify if $gatewayId and $datasourceId are populated by printing their values before making the API call. If they are empty, the dataset might not be properly mapped to a gateway. Furthermore, check the JSON request body structure—it appears to be missing a comma after "credentials", which could be causing the API to reject the request. You can restructure it by ensuring the credential details follow Power BI’s expected format.
To debug further, manually test the Power BI API by running Invoke-PowerBIRestMethod with a GET request to check if the dataset and gateway are correctly linked. If the error persists, confirm that the dataset is configured to use a gateway (if required) and that the workspace settings allow external connections. By addressing these potential issues, you should be able to resolve the error and successfully update the data source credentials in your Power BI deployment process.