Forum Discussion
DWD_76
Jul 05, 2022Copper Contributor
Help with Power BI REST API output
I have the following script that is using Invoke-PowerBIRestMethod. I have a couple of issues I need to help solving. 1. You can see I'm trying to convert the output of the API to a table or so...
LainRobertson
Jul 06, 2022Silver Contributor
I can't help with any live testing as I don't have PowerBI access, but running a search on a suspicion I had confirms that the results are in JSON form, meaning you're ConvertFrom-String should actually be ConvertFrom-Json.
Have a read of this old Microsoft blog for a broader overview.
I've also included the commandlet reference but it's not overly helpful from an examples perspective.
- Working with PowerShell in Power BI | Microsoft Power BI Blog | Microsoft Power BI
- Invoke-PowerBIRestMethod (MicrosoftPowerBIMgmt.Profile) | Microsoft Docs
Since I can't test against PowerBI, I'll offer a generic guide below on how to include the report GUID but you'll have to work on this yourself - unless someone else here has access and can do some testing for you.
In relation to the API reference (below), I can't tell if properties like principalType and reportUserAccessRight are single- or multi-valued. I've assumed the former but you'll be able to see that better than I.
This only relates to your Invoke-PowerBIRestMethod call. What you do before, after and with it is up to you.
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/admin/reports/$id/users" -Method Get |
ConvertFrom-Json |
ForEach-Object {
[PSCustomObject] @{
ReportId = $id;
PrincipalType = $_.principalType;
Identifier = $_.identifier;
Owner = $_.reportUserAccessRight -eq "Owner";
DisplayName = $_.displayName;
EmailAddress = $_.emailAddress;
}
}
Cheers,
Lain