<?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: Dataset refresh using Powershell without hardcoding password in the script in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Dataset-refresh-using-Powershell-without-hardcoding-password-in/m-p/2416527#M35148</link>
    <description>&lt;P&gt;Hi @Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can try to use a service principal to refresh the dataset with rest api.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://www.nickyvv.com/2020/06/refresh-a-power-bi-dataset-with-powershell-and-a-service-principal.html" target="_self"&gt;https://www.nickyvv.com/2020/06/refresh-a-power-bi-dataset-with-powershell-and-a-service-principal.html&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Liang&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 02:38:25 GMT</pubDate>
    <dc:creator>V-lianl-msft</dc:creator>
    <dc:date>2022-03-25T02:38:25Z</dc:date>
    <item>
      <title>Dataset refresh using Powershell without hardcoding password in the script</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Dataset-refresh-using-Powershell-without-hardcoding-password-in/m-p/2409530#M35103</link>
      <description>&lt;P&gt;I am trying to refresh a PowerBI dataset using a powershell script. But everytime I execute the script, it is asking for the credentials to sign in.&lt;/P&gt;&lt;P&gt;My requirement is to refresh the dataset using the powershell script which is triggered from the SQL Server Agent Job. I have created a proxy user account in SQL Server to execute the powershell script and I want the same credentials to be cascaded to the powershell script. I am not allowed to hardcode the password in the powershell script or read it from an encrypted file.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;When I am manually executing the script and enter the credentials in the pop-up window, the dataset is refreshed properly. But since i need to execute it from the SQL Server Agent Job, I need to avoid getting the pop-up asking for signing in.&lt;BR /&gt;I am using the below Powershell script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$groupID = "XXXXXXXXXXXXXXXXXXXX"
$datasetID = "XXXXXXXXXXXXXXXXXXXX"

$clientId = "XXXXXXXXXXXXXXXXXXXX"

function GetAuthToken
{
if(-not (Get-Module AzureRm.Profile)) {
Import-Module AzureRm.Profile
}

$redirectUri = "urn:ietf:wg:oauth:2.0:oob"

$resourceAppIdURI = "https://analysis.windows.net/powerbi/api"

$authority = "https://login.microsoftonline.com/common/oauth2/authorize";

$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority

$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")

return $authResult
}

# Get the auth token from AAD
$token = GetAuthToken

# Building Rest API header with authorization token
$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$token.CreateAuthorizationHeader()
}

# properly format groups path
$groupsPath = ""
if ($groupID -eq "me") {
$groupsPath = "myorg"
} else {
$groupsPath = "myorg/groups/$groupID"
}

# Refresh the dataset
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST -Verbose

# Check the refresh history
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET -Verbose&lt;/LI-CODE&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, 22 Mar 2022 12:59:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Dataset-refresh-using-Powershell-without-hardcoding-password-in/m-p/2409530#M35103</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-22T12:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset refresh using Powershell without hardcoding password in the script</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Dataset-refresh-using-Powershell-without-hardcoding-password-in/m-p/2416527#M35148</link>
      <description>&lt;P&gt;Hi @Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can try to use a service principal to refresh the dataset with rest api.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://www.nickyvv.com/2020/06/refresh-a-power-bi-dataset-with-powershell-and-a-service-principal.html" target="_self"&gt;https://www.nickyvv.com/2020/06/refresh-a-power-bi-dataset-with-powershell-and-a-service-principal.html&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Liang&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 02:38:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Dataset-refresh-using-Powershell-without-hardcoding-password-in/m-p/2416527#M35148</guid>
      <dc:creator>V-lianl-msft</dc:creator>
      <dc:date>2022-03-25T02:38:25Z</dc:date>
    </item>
  </channel>
</rss>

