<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Power BI REST API via Powershell: Create Datasource in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/593877#M18084</link>
    <description>&lt;P&gt;{&lt;BR /&gt;"datasourceType": "WEB",&lt;BR /&gt;"connectionDetails": "{\"url\":\"&lt;A href="http://app.powerbi.com\" target="_blank"&gt;http://app.powerbi.com\&lt;/A&gt;"}",&lt;BR /&gt;"datasourceName": "teststratumwebdatasource",&lt;BR /&gt;"credentialDetails": {&lt;BR /&gt;"credentialType": "Windows",&lt;BR /&gt;"credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"username\"},{\"name\":\"password\", \"value\":\"password\"}]}",&lt;BR /&gt;"encryptedConnection": "Encrypted",&lt;BR /&gt;"encryptionAlgorithm": "None",&lt;BR /&gt;"privacyLevel": "None"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to create datasource for web thru rest api which failed. does anyone else has an working example in this group for creating datasource using powerbi rest api calls&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Jan 2019 15:30:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-01-02T15:30:08Z</dc:date>
    <item>
      <title>Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/511934#M15793</link>
      <description>&lt;P&gt;I'm trying to automate gateway data source management using PowerShell. Sadly, the new MicrosoftPowerBIMgmt-Cmdlets don't provide commands for the &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways" target="_self"&gt;Gateway-REST-APIs&lt;/A&gt;. Instead there's &lt;A href="https://docs.microsoft.com/en-us/powershell/module/microsoftpowerbimgmt.profile/invoke-powerbirestmethod?view=powerbi-ps" target="_self"&gt;Invoke-PowerBIRestMethod&lt;/A&gt;&amp;nbsp;that I managed to use for almost all of the Gatewaway-APIs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the most important commands "&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource" target="_self"&gt;Create Datasource&lt;/A&gt;" and "&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource" target="_self"&gt;Update Datsource&lt;/A&gt;" resist my efforts. As seems to be the way of REST APIs, I don't get any useful error information, even when using&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/powershell/module/microsoftpowerbimgmt.profile/resolve-powerbierror?view=powerbi-ps" target="_self"&gt;Resolve-PowerBIError&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my Powershell code that tries to create a Dummy Web DataSource without any credentials (should be easy, right?):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#Import-Module -name microsoftpowerbimgmt
Connect-PowerBIServiceAccount
######## Create Datasource ########
$gatewayId = "&amp;lt;your GatewayId goes here&amp;gt;"
$URL = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId/datasources"
$Body = @{
    dataSourceType = "Web"
    datasourceName = "Dummy Web Connection"
    connectionDetails = "{`"path`":`"https://de.wikipedia.org/wiki/Liste_der_L%C3%A4nder_nach_Bruttoinlandsprodukt_pro_Kopf`"}"
    credentialDetails = @{
        credentialType = "Anonymous"
        credentials = "{`"credentialData`":`"`"}"
         encryptedConnection = "Encrypted"
        encryptionAlgorithm = "None"
        privacyLevel = "None"
    }
} | ConvertTo-Json
$Body
$response = Invoke-PowerBIRestMethod -Url $URL -Method POST -Body $Body&lt;/PRE&gt;&lt;P&gt;The $Body objects holds the following JSON which has the same format like shown in &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#anonymous_credentials_example" target="_self"&gt;this example&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
    "datasourceName":  "Dummy Web Connection",
    "credentialDetails":  {
                              "encryptedConnection":  "Encrypted",
                              "credentialType":  "Anonymous",
                              "credentials":  "{\"credentialData\":\"\"}",
                              "privacyLevel":  "None",
                              "encryptionAlgorithm":  "None"
                          },
    "dataSourceType":  "Web",
    "connectionDetails":  "{\"path\":\"https://de.wikipedia.org/wiki/Liste_der_L%C3%A4nder_nach_Bruttoinlandsprodukt_pro_Kopf\"}"
}&lt;/PRE&gt;&lt;P&gt;However, I always get a "Bad Request" answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody know how to fix my code to get the example running?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any hint is greatly appreciated! Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Sep 2018 13:47:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/511934#M15793</guid>
      <dc:creator>Sokon</dc:creator>
      <dc:date>2018-09-10T13:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513060#M15830</link>
      <description>&lt;P&gt;Hi, i know this is an old post... did you ever get it resolved?&lt;/P&gt;&lt;P&gt;I'm facing the exact same issue and have been begging for help, but no success...&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 17:31:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513060#M15830</guid>
      <dc:creator>Ronnie7</dc:creator>
      <dc:date>2018-09-11T17:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513580#M15839</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/16257"&gt;@Ronnie7&lt;/a&gt;: This is actually a brand new post!&amp;nbsp;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://community.fabric.microsoft.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;Nothing changed since, apart from a new idea: If we knew the URL to the YAML file we could use Swagger ourselves to get a possibly updated documentation...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 08:11:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513580#M15839</guid>
      <dc:creator>Sokon</dc:creator>
      <dc:date>2018-09-12T08:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513922#M15854</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/7023"&gt;@Sokon&lt;/a&gt;&amp;nbsp;i'm trying to create a new data source on a gateway via REST API&amp;nbsp; POST Method.&lt;/P&gt;&lt;P&gt;Here's the body of the request in JSON format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$body2='{&lt;BR /&gt;"dataSourceType": "SQL",&lt;BR /&gt;"connectionDetails": "{\"server\":\"test2\",\"database\":\"MyDatabase\"}",&lt;BR /&gt;"datasourceName": "Sample Datasource",&lt;BR /&gt;"credentialDetails": {&lt;BR /&gt;"credentialType": "Basic",&lt;BR /&gt;"credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"Myuser\"},{\"name\":\"password\", \"value\":\"***\"}]}",&lt;BR /&gt;"encryptedConnection": "Encrypted",&lt;BR /&gt;"encryptionAlgorithm": "None",&lt;BR /&gt;"privacyLevel": "None"&lt;BR /&gt;}&lt;BR /&gt;}'&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;{&lt;BR /&gt;Invoke-PowerBIRestMethod -url "&lt;A href="https://api.powerbi.com/v1.0/myorg/gateways/$GatewayID/datasources" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/gateways/$GatewayID/datasources&lt;/A&gt;" -Method post -body $body2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get error bad request 400... when i try to add this data source manually from the PowerBI administration GUI it's working.&lt;BR /&gt;If i'm using the GET method it's working as well and i can see all the data sources on that gateway...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 13:33:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513922#M15854</guid>
      <dc:creator>Ronnie7</dc:creator>
      <dc:date>2018-09-12T13:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513946#M15855</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/16257"&gt;@Ronnie7&lt;/a&gt;&amp;nbsp;There are some things I learned from experimenting with the (now working) PS-Code for the "&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/adddatasourceuser" target="_self"&gt;Add Datasource Users&lt;/A&gt;"-Command I can share:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Parameters seem to be case sensitive. "READ" is wrong "Read" worked. When you run the "Get Datasource" command, it will return "Sql" as dataSourceType and not "SQL".&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I can add Datasource Users only if the email addresses were valid. Fake or dummy addresses provoked an error. Perhaps that's the same with datasources. That's the reason why a tried to create a Web datasource with an anonymous authentication&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Automating-Power-BI-Gateway-administration-by-using-Powershell/td-p/207528" target="_self"&gt;Here is a similar thread&lt;/A&gt; where someone wants to use C# instead of PowerShell. Nevertheless, look at the part/discussion about the&amp;nbsp;credentials-tag: It's some kind of encrypted string that needed some clarification. Perhaps you understand that better than me?&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 12 Sep 2018 13:57:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513946#M15855</guid>
      <dc:creator>Sokon</dc:creator>
      <dc:date>2018-09-12T13:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513953#M15856</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/7023"&gt;@Sokon&lt;/a&gt;&amp;nbsp;thanks for the info.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen that thread that you mentioned, and I also struggle to understand it. Looks like we are missing something there...&lt;BR /&gt;I'll actually try to create a new &lt;STRONG&gt;web data&lt;/STRONG&gt; source with anonymouts login and see if that will work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;if so, i'll share the code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 14:11:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/513953#M15856</guid>
      <dc:creator>Ronnie7</dc:creator>
      <dc:date>2018-09-12T14:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/590293#M17980</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/7023"&gt;@Sokon&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/16257"&gt;@Ronnie7&lt;/a&gt;&amp;nbsp;did this work please share the code if yes i m facing similar issue&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 17:41:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/590293#M17980</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-12-21T17:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/593761#M18080</link>
      <description>&lt;P&gt;No progress here, sorry. But I posted an &lt;A href="https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/36428329-update-documentation-for-power-bi-rest-api-via-pow" target="_self"&gt;idea where you can vote&lt;/A&gt; for the documentation to be updated!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 13:11:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/593761#M18080</guid>
      <dc:creator>Sokon</dc:creator>
      <dc:date>2019-01-02T13:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/593877#M18084</link>
      <description>&lt;P&gt;{&lt;BR /&gt;"datasourceType": "WEB",&lt;BR /&gt;"connectionDetails": "{\"url\":\"&lt;A href="http://app.powerbi.com\" target="_blank"&gt;http://app.powerbi.com\&lt;/A&gt;"}",&lt;BR /&gt;"datasourceName": "teststratumwebdatasource",&lt;BR /&gt;"credentialDetails": {&lt;BR /&gt;"credentialType": "Windows",&lt;BR /&gt;"credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"username\"},{\"name\":\"password\", \"value\":\"password\"}]}",&lt;BR /&gt;"encryptedConnection": "Encrypted",&lt;BR /&gt;"encryptionAlgorithm": "None",&lt;BR /&gt;"privacyLevel": "None"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to create datasource for web thru rest api which failed. does anyone else has an working example in this group for creating datasource using powerbi rest api calls&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 15:30:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/593877#M18084</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-01-02T15:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/701507#M19512</link>
      <description>&lt;P&gt;BUMP&lt;BR /&gt;&lt;BR /&gt;I've found that there are lack of specification of parameters in body in documentation&lt;BR /&gt;For examaple what should the body look like&amp;nbsp;when we want setting new datasource of SQL in gateway?&lt;BR /&gt;Here are some threads without reply (last link is mine):&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Problem-with-creating-datasource-under-gateway-through-API/td-p/414814" target="_blank"&gt;https://community.powerbi.com/t5/Developer/Problem-with-creating-datasource-under-gateway-through-API/td-p/414814&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Developer/PowerBI-REST-API-error-Need-help/td-p/509452" target="_blank"&gt;https://community.powerbi.com/t5/Developer/PowerBI-REST-API-error-Need-help/td-p/509452&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/td-p/695814/jump-to/first-unread-message" target="_blank"&gt;https://community.powerbi.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/td-p/695814/jump-to/first-unread-message&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;If any of you know the answer please share correct examples.&lt;BR /&gt;MS please make up your documentation:&amp;nbsp;&lt;A title="" href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource" target="_blank" rel="noopener nofollow noopener noreferrer"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Greetings&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 14:54:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/701507#M19512</guid>
      <dc:creator>sm3</dc:creator>
      <dc:date>2019-05-28T14:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/811047#M21015</link>
      <description>&lt;P&gt;The credentials from credentialDetails need to be encripted unsing RSA &lt;SPAN&gt;algorithm&amp;nbsp;before calling the api. I've used an alghorthim posted in&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243" target="_self"&gt;https://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243&lt;/A&gt;&amp;nbsp;and converted it to powershell. The algorithm from&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/encrypt-credentials" target="_blank"&gt;https://docs.microsoft.com/en-us/power-bi/developer/encrypt-credentials&lt;/A&gt;&amp;nbsp;is also good. Also the server name needs to have double the amount of&amp;nbsp;"\" charahters to work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function CreateDatasourceForGateway([guid]$GatewayId, 
                                    [string]$DatasourceName, 
                                    [string]$TenantServer, 
                                    [string]$TenantDatabase,
                                    [string]$TenantDataSourceUser,
                                    [string]$TenantDataSourcePassword) {   

    $gateway = Invoke-PowerBIRestMethod `
                -Url "https://api.powerbi.com/v1.0/myorg/gateways/$GatewayId" `
                -Method GET ` | ConvertFrom-Json                

    $datasourceDetails = ConvertTo-Json -Depth 4 -InputObject $(@{
        dataSourceType = "Sql"
        connectionDetails = '{"server":"'+$TenantServer.Replace("\","\\")+'","database":"'+$TenantDatabase+'"}'
        datasourceName = $DatasourceName
        credentialDetails = @{
            credentialType = "Basic"
            credentials = Encript `
                            -Username $TenantDataSourceUser `
                            -Password $TenantDataSourcePassword `
                            -GatewayExponent $gateway.publicKey.exponent `
                            -GatewayModulus $gateway.publicKey.modulus
            encryptedConnection = "Encrypted"
            encryptionAlgorithm = "RSA-OAEP"
            privacyLevel = "None"
        }
    })

    $result = Invoke-PowerBIRestMethod `
            -Url "https://api.powerbi.com/v1.0/myorg/gateways/$GatewayId/datasources" `
            -Method POST `
            -Body $datasourceDetails
}

function Encript([string]$Username,[string]$Password,[string]$GatewayExponent,[string]$GatewayModulus) {
    $segmentLength = 85
    $encryptedLength = 128
    $plaintTxt = '{"credentialData":[{"value":"'+$Username+'","name":"username"},{"value":"'+$Password+'","name":"password"}]}'
    $rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider ($encryptedLength * 8)
    $parameters = $rsa.ExportParameters($false)
    $parameters.Exponent = [System.Convert]::FromBase64String($GatewayExponent)
    $parameters.Modulus = [System.Convert]::FromBase64String($GatewayModulus)
    $rsa.ImportParameters($parameters)
    $plainTextArray = [System.Text.Encoding]::UTF8.GetBytes($plaintTxt)    
    $hasIncompleteSegment = $plainTextArray.Length % $segmentLength -ne 0

    $segmentNumber = If (-not $hasIncompleteSegment) {[int]($plainTextArray.Length / $segmentLength)} Else {[int]($plainTextArray.Length / $segmentLength) + 1}
    $encryptedData = [System.Byte[]]::CreateInstance([System.Byte],$segmentNumber * $encryptedLength)
    [int]$encryptedDataPosition = 0;

    For ($i=0; $i -lt $segmentNumber; $i++) {
        $lengthToCopy = If ($i -eq ($segmentNumber - 1) -and $hasIncompleteSegment) {$plainTextArray.Length % $segmentLength} Else {$segmentLength}
        $segment = [System.Byte[]]::CreateInstance([System.Byte],$lengthToCopy)
        [System.Array]::Copy($plainTextArray,$i*$segmentLength,$segment,0,$lengthToCopy)
        $segmentEncryptedResult = $rsa.Encrypt($segment, $true)
        [System.Array]::Copy($segmentEncryptedResult,0,$encryptedData,$encryptedDataPosition,$segmentEncryptedResult.Length)
        $encryptedDataPosition += $segmentEncryptedResult.Length;
    }

    return [System.Convert]::ToBase64String($encryptedData)
}

Connect-PowerBIServiceAccount

CreateDatasourceForGateway `
    -GatewayId $GatewayId `
    -DatasourceName "$TenantReportPrefix Datasource"`
    -TenantServer $TenantServer `
    -TenantDatabase $TenantDatabase `
    -TenantDataSourceUser $TenantDataSourceUser `
    -TenantDataSourcePassword $TenantDataSourcePassword&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 08:04:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/811047#M21015</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-10-07T08:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/862285#M21606</link>
      <description>&lt;P&gt;Thanks a LOT !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Got stuck couple of hours only to found out what you suggested:&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;--&amp;gt; Also the server name needs to have double the amount of&amp;nbsp;"\" charahters to work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 14:09:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/862285#M21606</guid>
      <dc:creator>pbiembed4</dc:creator>
      <dc:date>2019-12-02T14:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/1377699#M25761</link>
      <description>&lt;P&gt;Anyone figured out how to &lt;STRONG&gt;add a datasource without encryption and without credentials&lt;/STRONG&gt; like the checkbox "skip test connection"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using "anonymus" credential type but that did not work yet in my tests.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 12:53:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/1377699#M25761</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-17T12:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI REST API via Powershell: Create Datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/1425370#M26065</link>
      <description>&lt;P&gt;Hi Alex,&lt;/P&gt;&lt;P&gt;I am getting this weird error message when used your code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;Invoke-PowerBIRestMethod : One or more errors occurred.&lt;BR /&gt;At line:29 char:15&lt;BR /&gt;+ $result = Invoke-PowerBIRestMethod `&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException&lt;BR /&gt;+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With&amp;nbsp;resolve-azerror -last&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;WARNING: Breaking changes in the cmdlet 'Resolve-AzError' :&lt;BR /&gt;WARNING: - The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;WARNING: NOTE : Go to &lt;A href="https://aka.ms/azps-changewarnings" target="_blank" rel="noopener"&gt;https://aka.ms/azps-changewarnings&lt;/A&gt; for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;HistoryId: 7&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Message : Response status code does not indicate success: 400 (Bad Request).&lt;BR /&gt;StackTrace : at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()&lt;BR /&gt;at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.&amp;lt;InvokeRestMethod&amp;gt;d__31.MoveNext()&lt;BR /&gt;Exception : System.Net.Http.HttpRequestException&lt;BR /&gt;InvocationInfo : {Invoke-PowerBIRestMethod}&lt;BR /&gt;Line : $result = Invoke-PowerBIRestMethod `&lt;BR /&gt;&lt;BR /&gt;Position : At line:29 char:15&lt;BR /&gt;+ $result = Invoke-PowerBIRestMethod `&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;HistoryId : 7&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The Azure PowerShell team is listening, please let us know how we are doing: &lt;A href="https://aka.ms/azpssurvey?Q_CHL=FEEDBACK" target="_blank" rel="noopener"&gt;https://aka.ms/azpssurvey?Q_CHL=FEEDBACK&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I need to have Power Bi Admin permissions ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have full administrative permissions on Power Bi gateway where trying to build this data source.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 03:04:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/m-p/1425370#M26065</guid>
      <dc:creator>niravmodi</dc:creator>
      <dc:date>2020-10-10T03:04:13Z</dc:date>
    </item>
  </channel>
</rss>

