<?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 API via PowerShell fails in Azure DevOps in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/769431#M20426</link>
    <description>&lt;P&gt;This doesn't work because the Power BI cmdlets don't accept service principals for most operations. For example:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2019-08-19 08_23_01-Clipboard.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/185774i6B2E9922A413C341/image-size/large?v=v2&amp;amp;px=999" role="button" title="2019-08-19 08_23_01-Clipboard.png" alt="2019-08-19 08_23_01-Clipboard.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore I'm trying to login using a native app (instead of web app) using the code I posted in the OP. That works perfectly fine in Windows, just not in DevOps.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Aug 2019 06:24:20 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-08-19T06:24:20Z</dc:date>
    <item>
      <title>Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/763984#M20326</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to automate the deployment of Power BI (and other modern DWH components) via Azure DevOps releases. I've created a PowerShell script that looks at the contents of a setup file in my repository and then starts creating workspaces (if they don't exist) and publish reports to these workspaces.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Everything works fine when I run the PowerShell script on my local laptop. It hangs when I run it in DevOps. I've narrowed the issue down to the authentication part of the script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use an app registration to authenticate against Power BI. This works. The first time I ran the script I had to assign rights to the app, and now it just works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My script below (simplified to demo the issue)&lt;/P&gt;&lt;PRE&gt;$clientId = "xyz" -- clientId of app here
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
}

$token = GetAuthToken

# Building Rest API header with authorization token
$auth_header = @{
   'Content-Type'='application/json'
   'Authorization'=$token.CreateAuthorizationHeader()
} 

$target_group_name = "ABC Test Workspace"
$uri = "https://api.powerbi.com/v1.0/myorg/groups"
$body = "{`"name`":`"$target_group_name`"}"
$response = Invoke-RestMethod -Uri $uri –Headers $auth_header –Method POST -Body $body
Write-Host $response.id&lt;/PRE&gt;&lt;P&gt;What happens is that on the AcquireToken function, a popup window (the authentication window) opens up and then immediately closes (because the app is already authenticated).&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, in DevOps, the script seems to hang on this popup. When I run this in Windows the script continues past the popup and creates the Power BI workspace called "ABC Test Workspace". In DevOps, nothing happens and I have to cancel the operation manually.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody have an idea how to solve this? It would be great to have a working DevOps pipeline to do CI/CD stuff with Power BI from your repositories.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bas&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 09:09:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/763984#M20326</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-12T09:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/767386#M20374</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure that you aware of the Azure DevOps Extension called &lt;A href="https://marketplace.visualstudio.com/items?itemName=maikvandergaag.maikvandergaag-power-bi-actions" target="_blank" rel="noopener"&gt;PowerBI Action&lt;/A&gt;. Using this you can do some operation easily with out having worry about powershell scripts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you still want to do some additional things , you can see the source code of the extension, where the author is also using powershell to build this extension.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The author put all the powershell cleanly in a function, &lt;A href="https://github.com/maikvandergaag/msft-extensions/blob/master/azuredevops/powerbiactions/powerbiactions/ps_modules/PowerBi/powerbi.psm1#L13" target="_self"&gt;as per that&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Function Get-AADToken {
    Param(
        [parameter(Mandatory = $true)][string]$Username,
        [parameter(Mandatory = $true)][SecureString]$Password,
        [parameter(Mandatory = $true)][guid]$ClientId,
        [parameter(Mandatory = $true)][string]$Resource
    )

    $authorityUrl = "https://login.microsoftonline.com/common/oauth2/authorize"

    ## load active directory client dll
    $typePath = $PSScriptRoot + "\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
    Add-Type -Path $typePath 

    Write-Verbose "Loaded the Microsoft.IdentityModel.Clients.ActiveDirectory.dll"

    Write-Verbose "Using authority: $authorityUrl"
    $authContext = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext -ArgumentList ($authorityUrl)
    $credential = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential -ArgumentList ($UserName, $Password)
    
    Write-Verbose "Trying to aquire token for resource: $Resource"
    $authResult = $authContext.AcquireToken($Resource, $clientId, $credential)

    Write-Verbose "Authentication Result retrieved for: $($authResult.UserInfo.DisplayableId)"
    return $authResult.AccessToken
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I'm also writing a detailed article for CICD for PowerBI using Azure DevOps,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://social.technet.microsoft.com/wiki/contents/articles/53172.azuredevops-cicd-for-powerbi-reports.aspx" target="_blank"&gt;https://social.technet.microsoft.com/wiki/contents/articles/53172.azuredevops-cicd-for-powerbi-reports.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it's still in progress, I stil need some time to need these too&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;</description>
      <pubDate>Thu, 15 Aug 2019 09:08:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/767386#M20374</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2019-08-15T09:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/767449#M20376</link>
      <description>&lt;P&gt;The reason I can't use Power BI Actions (I tried!) is that it needs a username and password. This is not acceptible for our clients. Best practice is to use a client id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Via PowerShell this is 100% possible. In fact the scripts work when I run them locally on my laptop. They seem to get stuck on the authentication part when I run them as part of a DevOps pipeline.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm interested in your blog article!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 10:15:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/767449#M20376</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-15T10:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/767488#M20377</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok could you please try my script below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$applicationId = "xxxxxxxx";
$securePassword = "xxxxxx" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "xxxx"&lt;/PRE&gt;&lt;P&gt;Which is using the Client ID autentication part.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also provided this &lt;A href="https://stackoverflow.com/a/57344477/7073340" target="_blank" rel="noopener"&gt;answer in SO&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By this way it will work in both your local and azure devops&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 11:32:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/767488#M20377</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2019-08-15T11:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/769431#M20426</link>
      <description>&lt;P&gt;This doesn't work because the Power BI cmdlets don't accept service principals for most operations. For example:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2019-08-19 08_23_01-Clipboard.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/185774i6B2E9922A413C341/image-size/large?v=v2&amp;amp;px=999" role="button" title="2019-08-19 08_23_01-Clipboard.png" alt="2019-08-19 08_23_01-Clipboard.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore I'm trying to login using a native app (instead of web app) using the code I posted in the OP. That works perfectly fine in Windows, just not in DevOps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 06:24:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/769431#M20426</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-19T06:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/769435#M20427</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should work. I think you are in luck today. I've just completed my Article&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://social.technet.microsoft.com/wiki/contents/articles/53172.azuredevops-cicd-for-powerbi-reports.aspx" target="_blank" rel="noopener"&gt;https://social.technet.microsoft.com/wiki/contents/articles/53172.azuredevops-cicd-for-powerbi-reports.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Download Full code&lt;/P&gt;&lt;P&gt;&lt;A href="https://gallery.technet.microsoft.com/AzureDevOps-CICD-for-fefd58b8" target="_blank"&gt;https://gallery.technet.microsoft.com/AzureDevOps-CICD-for-fefd58b8&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've explained all in details about in this article. It would help you. Best of luck !&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 06:30:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/769435#M20427</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2019-08-19T06:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API via PowerShell fails in Azure DevOps</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/784264#M20652</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any update ? If my replay helps please accept it as answer/giving kudos which will help other community members&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 06:22:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-via-PowerShell-fails-in-Azure-DevOps/m-p/784264#M20652</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2019-09-05T06:22:23Z</dc:date>
    </item>
  </channel>
</rss>

