Share via

PowerShell & Power BI Rest API - Export-Csv

Quisty 1 Reputation point
2021-09-17T08:32:04.71+00:00

Hi

Essentially what I'm after is the results of rest API Gateways - Get Datasource Users but retaining the ID (in this example $Line.id from my imported CSV file).

The end result should be a CSV with the following fields -
ID, emailAddress, datasourceAccessRight, displayName, identifier, principalType

I'm new to PowerShell and suprised I got this far but can't figure out this final bit.

Cheers

$webclient=New-Object System.Net.WebClient  
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials  
  
$Dir = "C:\pbi_pro_user_logs\"  
  
Login-PowerBI  
  
$GateWayFile = Import-CSV -Path "C:\pbi_pro_user_logs\Gateway_Detail.csv"  
$Output = @()  
foreach ($Line in $GateWayFile)  
    {  
    $Item = $Line.id  
    $url =  "https://api.powerbi.com/v1.0/myorg/gateways/HIDDEN/datasources/"+$Item+"/users"  
    $Output += (Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json)  
    }  
  
$Result = $Output.value  
  
$Result | Export-Csv $Dir"GateWay_users.csv" -NoTypeInformation  
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Limitless Technology 40,101 Reputation points
    2021-09-17T13:33:14.907+00:00

    Hello @Quisty ,

    Thank you for your question.

    As you don't have much experience with PowerShell, I recommend that you consult the article below to know how to deal with this type of scenario:

    https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file

    If the answer was helpful, please don't forget to vote positively or accept as an answer, thank you.

    Yours sincerely,

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.