<?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: Authentication in Powershell and API to update a dataset. in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/230094#M7248</link>
    <description>&lt;P&gt;Yes there are examples of how to do it silently in powershell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#region username and password
#$user = "username"
#$pass = "password" | ConvertTo-SecureString -AsPlainText -Force

#$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
#$authToken = Get-PBIAuthToken -ClientId "ZZZZZZZZ-XXX-blah-blah-Muffins" -Credential $cred&lt;/PRE&gt;&lt;P&gt;The issue is what type of user account does it have to be to simply push data to the datasets? And is there a way of doing it without storing the password in the script?&lt;/P&gt;</description>
    <pubDate>Fri, 11 Aug 2017 14:39:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-08-11T14:39:47Z</dc:date>
    <item>
      <title>Authentication in Powershell and API to update a dataset.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/229470#M7235</link>
      <description>&lt;P&gt;I have a working Powershell script that runs a SQL query and creates/updates results to a PowerBI dataset. The trouble is it uses my own SSO login to do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to run this as a task/service to update the dataset every X minutes. I'm looking to simplify authentication. Right now it seems I need an O365 account + PowerBI Pro user just to push data up with the API. Is that correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On Datasets made thru the Desktop I can change the username and password. But this is not true on datasets made through the API and set to "Push". (Data sets is created using the New-PBIDataSet function from PowerBIPS powershell module.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this with a simple user/pass account? Or is there an API key method like in Amazon AWS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see threads like this, but they talk about app accesss, not dataset updating.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/REST-API-Silent-Authentication-Token/m-p/156004#M5283" target="_blank"&gt;https://community.powerbi.com/t5/Developer/REST-API-Silent-Authentication-Token/m-p/156004#M5283&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 18:28:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/229470#M7235</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-10T18:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication in Powershell and API to update a dataset.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/229656#M7236</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a working Powershell script that runs a SQL query and creates/updates results to a PowerBI dataset. The trouble is it uses my own SSO login to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to run this as a task/service to update the dataset every X minutes. I'm looking to simplify authentication. Right now it seems I need an O365 account + PowerBI Pro user just to push data up with the API. Is that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On Datasets made thru the Desktop I can change the username and password. But this is not true on datasets made through the API and set to "Push". (Data sets is created using the New-PBIDataSet function from PowerBIPS powershell module.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to do this with a simple user/pass account? Or is there an API key method like in Amazon AWS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see threads like this, but they talk about app accesss, &lt;STRONG&gt;not dataset updating.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/REST-API-Silent-Authentication-Token/m-p/156004#M5283" target="_blank"&gt;https://community.powerbi.com/t5/Developer/REST-API-Silent-Authentication-Token/m-p/156004#M5283&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@Anonymous&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The dataset updateing is based on the accesstoken. To get the accesstoken in a silent way, I use the way in C# as below. You could follow the same in way in PowerShell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;static string getAccessTokenSilently()
        {

            HttpWebRequest request = System.Net.HttpWebRequest.CreateHttp("https://login.windows.net/common/oauth2/token");
            //POST web request to create a datasource.
            request.KeepAlive = true;
            request.Method = "POST";
            request.ContentLength = 0;
            request.ContentType = "application/x-www-form-urlencoded";

            //Add token to the request header
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token));

            NameValueCollection parsedQueryString = HttpUtility.ParseQueryString(String.Empty);&lt;BR /&gt;            //To learn how to get a client app ID, see Register a client app (https://msdn.microsoft.com/en-US/library/dn877542.aspx#clientID)
            parsedQueryString.Add("client_id", clientID);
            parsedQueryString.Add("grant_type", "password");
            parsedQueryString.Add("resource", "https://analysis.windows.net/powerbi/api");
            parsedQueryString.Add("username", username); //your power bi account here
            parsedQueryString.Add("password", password);  //your power bi password here
            string postdata = parsedQueryString.ToString();


            //POST web request
            byte[] dataByteArray = System.Text.Encoding.ASCII.GetBytes(postdata); ;
            request.ContentLength = dataByteArray.Length;

            //Write JSON byte[] into a Stream
            using (Stream writer = request.GetRequestStream())
            {
                writer.Write(dataByteArray, 0, dataByteArray.Length);
                var response = (HttpWebResponse)request.GetResponse();
                var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                dynamic responseJson = JsonConvert.DeserializeObject&amp;lt;dynamic&amp;gt;(responseString);
                return responseJson["access_token"];
            }


        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 02:55:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/229656#M7236</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-08-11T02:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication in Powershell and API to update a dataset.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/230094#M7248</link>
      <description>&lt;P&gt;Yes there are examples of how to do it silently in powershell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#region username and password
#$user = "username"
#$pass = "password" | ConvertTo-SecureString -AsPlainText -Force

#$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
#$authToken = Get-PBIAuthToken -ClientId "ZZZZZZZZ-XXX-blah-blah-Muffins" -Credential $cred&lt;/PRE&gt;&lt;P&gt;The issue is what type of user account does it have to be to simply push data to the datasets? And is there a way of doing it without storing the password in the script?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 14:39:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/230094#M7248</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-11T14:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication in Powershell and API to update a dataset.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/231761#M7308</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently using PowerShell via SQL Agent to run a .ps1 file that calls the refresh API for some of my datasets. &amp;nbsp;In order to for the account to access powerBi it must exist in Azure Active Directory and have a PowerBI account (a pro account may be needed depending on what you're doing). &amp;nbsp;I can't speak for how your organization is structured but for me, I had our Infastructure guys create a service account in our local AD and give it an O365 account. &amp;nbsp;Once that is done, the account is synced to Azure AD. &amp;nbsp;I then had them give the account a PBI pro license as it's being used as a service account for embedding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I created a powershell script and I'm using those credentials to create the access token. &amp;nbsp;As far as not hard coding the PW into the script, I actually created a text file with an encrypted string. &amp;nbsp;This file is pulled into the script and decrypted at run time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code snippet that pulls in the file and decrypts it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#Get the root folder of this file
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

#Get the fully qualified filename
$pwdFile = "$PSScriptRoot\$pwdFileName"

#Create the key
$key = (1..16)

#Decrypt the pw
$password = Get-Content -LiteralPath $pwdFile | ConvertTo-SecureString -Key $key&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a link to my post with some code snippets...Note that in my post I'm still using the hard coded PW. &amp;nbsp;I changed it to a secure file after my post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/programmatic-data-refresh-using-api/m-p/223051#M7045" target="_self"&gt;https://community.powerbi.com/t5/Developer/programmatic-data-refresh-using-api/m-p/223051#M7045&lt;/A&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>Tue, 15 Aug 2017 16:14:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/231761#M7308</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-15T16:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication in Powershell and API to update a dataset.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/231838#M7314</link>
      <description>&lt;P&gt;Ooh, this looks promising! I'll give this a lookover tomorrow. Thanks rossnruthie!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 19:57:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authentication-in-Powershell-and-API-to-update-a-dataset/m-p/231838#M7314</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-15T19:57:23Z</dc:date>
    </item>
  </channel>
</rss>

