question

Quisty-2836 avatar image
0 Votes"
Quisty-2836 asked LimitlessTechnology-2700 answered

PowerShell & Power BI Rest API - Export-Csv

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello @Quisty-2836,


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://docs.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,

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.