Forum Discussion
Getting error using Power Shell Script to update data sources.
Hi Anonymous ,
Thank you for the response. I verified the permissions and all the permission are already given to service principal. Also tried the above solution, but getting below error:
Invoke-PowerBIRestMethod : Encountered errors when invoking the command: {
"code": "BadRequest",
"message": "Bad Request",
"details": [
{
"message": "Invalid value",
"target": "datasourceDelta"
}
]
}
Hi rajeshlohar1974 ,
The following links are the ones which has the similar requirement as yours, hope its solution can help you.
Solved: Update Datasource Credential Using Only Powershell... - Microsoft Fabric Community
PowerBI-Developer-Samples/PowerShell Scripts/EncryptGatewayCredentials.ps1 at master
# Basic Credentials
function EncryptBasicCredentials {
param (
[Parameter(Mandatory=$True,Position=1)]
[String]$Username,
[Parameter(Mandatory=$True,Position=2)]
[String]$PasswordAsString,
[Parameter(Mandatory=$True,Position=3)]
[string]$GatewayExponent,
[Parameter(Mandatory=$True,Position=4)]
[string]$GatewayModulus
)
# Create the objects to perform the necessary encryption on the credentials.
$gatewayKeyObj = [Microsoft.PowerBI.Api.Models.GatewayPublicKey]::new($GatewayExponent, $GatewayModulus)
$credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj)
$basicCreds = [Microsoft.PowerBI.Api.Models.Credentials.BasicCredentials]::new($username, $PasswordAsString)
# Construct the CredentialDetails object. The resulting "Credentials" property on this object will have been encrypted appropriately, ready for use in the request payload.
$credentialDetails = [Microsoft.PowerBI.Api.Models.CredentialDetails]::new(
$basicCreds,
[Microsoft.PowerBI.Api.Models.PrivacyLevel]::Organizational,
[Microsoft.PowerBI.Api.Models.EncryptedConnection]::Encrypted,
$credentialsEncryptor)
# Construct the body for the API request.
$body = @{
credentialDetails = @{
credentialType = "Basic";
credentials = $credentialDetails.Credentials;
encryptedConnection = "Encrypted";
encryptionAlgorithm = "RSA-OAEP";
privacyLevel = "Organizational";
}
}
$bodyJson = $body | ConvertTo-Json
Write-Output $bodyJson
}
Best Regards
- rajeshlohar19741 year agoFrequent Visitor
Hello Anonymous ,
I tried the above, but still not working.
I have a power bi report connected with an on-premises data source using on-premises data gateway. When I publish report to workspace, it is working well but when I publish report using CI/CD pipeline from Development to Production workspace, then I need to update datasource like database name and credentials. I am able to update database name and server name using /default.updateparameters API, but getting error in updating credentials.
Also I found that gateway ID getting from dataset is different from gateway ID on Power BI, it seems it updates when parameters updated.
Suggest possible solution.