Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

timmac

[SUPPORT-INFO]: Export-PowerBIReport returns: invalid status code 'Unauthorized'

PRODUCTS INVOLVED

Microsoft Power BI Service and Desktop / Reports

Microsoft Windows PowerShell

PROBLEM SCENARIO DESCRIPTION

Executing the PowerShell cmdlet Export-PowerBIReport we receive the below mention error message

ERROR

Export-PowerBIReport : Operation returned an invalid status code 'Unauthorized'

At E:\Scripts\pbiExportPowerBIReport.ps1:2 char:1

+ Export-PowerBIReport -Id f74199d0-20e3-4946-9764-a80f60a5541c -OutFil ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : WriteError: (Microsoft.Power...rtPowerBIReport:ExportPowerBIReport) [Export-PowerBIReport], HttpOperationException

    + FullyQualifiedErrorId : Operation returned an invalid status code 'Unauthorized',Microsoft.PowerBI.Commands.Reports.ExportPowerBIReport

CAUSE

This can be caused for several reasons:

 

  1. If you omit the WorkspaceID parameter and the report resides in a workspace that is different than "My Workspace".

    NOTE: WorkspaceId defaults to "My Workspace" if the parameter is not specified.  If the report resides in a workspace that is different than "My Workspace", then you will need to provide a WorkspaceId.
     
  2. If the ID and/or the WorkspaceID is invalid
  3. If you are missing the PBIX file upload from Power BI Desktop

    NOTE: If you utilize the samples, be sure to download the PBIX files to ensure that you can upload them to the Power BI Service.   

SAMPLE SCRIPT

Export-PowerBIReport -Id <Power BI Report ID> -OutFile 'D:\my.pbix2'

This script is missing the WorkspaceID parameter.

If the report does not exist in the My Workspace workspace, then this will return the 'Unauthorized' error message.

 

Export-PowerBIReport -Id <Power BI Report ID> -WorkspaceId <Invalid Workspace ID> -OutFile 'D:\my.pbix2'

If either the Report ID (-id) and/or the Workspace ID (-Workspaceid) is invalid, the 'Unauthorized' error message will be returned.

 

Export-PowerBIReport -Id <Power BI Report ID> -WorkspaceId <Power BI Workspace ID> -OutFile 'D:\my.pbix2'

If you did not upload the PBIX file from Power BI Desktop to the Power BI Service, and there is no PBIX file associated, then the 'Unauthorized' error message will be returned.

Export Report to Power BI Desktop (Preview): https://docs.microsoft.com/en-us/power-bi/service-export-to-pbix#considerations-and-troubleshooting

pbiconsiderations.JPG

 

RESOLUTION

To resolve this issue, you need to ensure the following:

 

  1. Ensure that the parameters (Id and/or WorkspaceId) are valid
  2. Ensure that you have uploaded a PBIX file from Power BI Desktop to the Power BI Workspace / Service

ADDITIONAL RESOURCES / LINKS