Forum Discussion
Anonymous
4 years agoNot applicable
encrypt credentials to create datasource - PowerShell
I'm trying to automate gateway data source management using PowerShell. First I need to encrypt credentials. Here is my PowerShell script to do this; $segmentLength = 85
$encryptedLength = 128
$pla...
- 4 years ago
Hi Anonymous ,
See if this sample will help you:
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Sébastien
3 years agoNew Member
Hello, here is my function, i found some code in the past available from internet.
In this function, it assumes that you already have imported the MicrosoftPowerBiMgmt modules
You need to download the Microsoft.PowerBI.Api.dll in order to call some code:
<#
.Synopsis
Encrypt the credentials against a DataGateway
#>
function Get-EncryptedCredentialDetails
{
param
(
# The Username
[parameter(Mandatory=$true)][string]$Username,
# The Password
[parameter(Mandatory=$true)][string]$Password,
# The DataGateway ID
[parameter(Mandatory=$true)][string]$DataGatewayId
)
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\Microsoft\Microsoft.PowerBI.Api.dll")
$publicKey = (Invoke-PowerBIRestMethod -Url gateways/$($DataGatewayId) -Method Get | ConvertFrom-Json).publicKey
$gatewayPublicKey = [Microsoft.PowerBI.Api.Models.GatewayPublicKey]::new($publicKey.exponent, $publicKey.modulus)
$basicCredentials = [Microsoft.PowerBI.Api.Models.Credentials.BasicCredentials]::new($Username, $Password)
$credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayPublicKey)
[Microsoft.PowerBI.Api.Models.CredentialDetails]::new(
$basicCredentials,
[Microsoft.PowerBI.Api.Models.PrivacyLevel]::Organizational,
[Microsoft.PowerBI.Api.Models.EncryptedConnection]::Encrypted,
$credentialsEncryptor)
}