Code Monkey home page Code Monkey logo

powerbi-powershell's Introduction

Microsoft Power BI Cmdlets for Windows PowerShell and PowerShell Core

Welcome to the PowerShell community for Microsoft Power BI. Here you will find resources and source for PowerShell modules targeting PowerBI.

For questions or issues using the modules, please log an issue and we will respond as quickly as possible.

PowerShell modules

Below is a table of the various Power BI PowerShell modules found in this repository.

Description Module Name PowerShell Gallery link
Rollup Module for Power BI Cmdlets MicrosoftPowerBIMgmt MicrosoftPowerBIMgmt
Admin module for Power BI MicrosoftPowerBIMgmt.Admin MicrosoftPowerBIMgmt.Admin
Capacities module for Power BI MicrosoftPowerBIMgmt.Capacities MicrosoftPowerBIMgmt.Capacities
Data module for Power BI MicrosoftPowerBIMgmt.Data MicrosoftPowerBIMgmt.Data
Profile module for Power BI MicrosoftPowerBIMgmt.Profile MicrosoftPowerBIMgmt.Profile
Reports module for Power BI MicrosoftPowerBIMgmt.Reports MicrosoftPowerBIMgmt.Reports
Workspaces module for Power BI MicrosoftPowerBIMgmt.Workspaces MicrosoftPowerBIMgmt.Workspaces

More documentation can be found at https://docs.microsoft.com/en-us/powershell/power-bi/overview.

Supported environments and PowerShell versions

  • Windows PowerShell v3.0 and up with .NET 4.7.1 or above.
  • PowerShell Core (v6) and up on any OS platform supported by PowerShell Core.

Installation

The cmdlets are available on PowerShell Gallery and can be installed in an elevated PowerShell session:

Install-Module -Name MicrosoftPowerBIMgmt

Optionally you could install individual modules (based on your needs) instead of the rollup module, for example if you only wanted the Workspaces module:

Install-Module -Name MicrosoftPowerBIMgmt.Workspaces

If you have an earlier version, you can update to the latest version by running:

Update-Module -Name MicrosoftPowerBIMgmt

Uninstall

If you want to uninstall all the Power BI PowerShell cmdlets, run the following in an elevated PowerShell session:

Get-Module MicrosoftPowerBIMgmt* -ListAvailable | Uninstall-Module -Force

Usage

Two scopes are supported by cmdlets that interact with Power BI entities:

  • Individual is used to access entities that belong to the current user.
  • Organization is used to access entities across the entire company. Only Power BI tenant admins are allowed to use.

If the -Scope parameter doesn't exist on the cmdlet, the entity doesn't support an Administrative API.

Log in to Power BI

Connect-PowerBIServiceAccount   # or use aliases: Login-PowerBIServiceAccount, Login-PowerBI

Use the Environment parameter if you need other than Public, which is default. Options are Germany, USGov, China, USGovHigh, USGovMil.

Connect-PowerBIServiceAccount -Environment China

Get workspaces

Get workspaces for the user. By default (i.e. without -First parameter) it shows the first 100 workspaces assigned to the user:

Get-PowerBIWorkspace

Use the -All parameter to show all workspaces assigned to the user:

Get-PowerBIWorkspace -All

If you are a tenant administrator, you can view all workspaces in your tenant by adding -Scope Organization:

Get-PowerBIWorkspace -Scope Organization -All

Update workspace

Update the name or description of a user's workspace:

Set-PowerBIWorkspace -Scope Organization -Id "3244f1c1-01cf-457f-9383-6035e4950fdc" -Name "Test Name" -Description "Test Description"

Add new user to workspace

Add a user to a given workspace:

Add-PowerBIWorkspaceUser -Scope Organization -Id 3244f1c1-01cf-457f-9383-6035e4950fdc -UserEmailAddress john@contoso.com -AccessRight Admin

Add new service principal to workspace

Add a service principal to a given workspace:

Add-PowerBIWorkspaceUser -WorkspaceId 3244f1c1-01cf-457f-9383-6035e4950fdc -Identifier "09934a8f-5066-44b2-91a6-f4987c76ae9e" -AccessRight Contributor -PrincipalType App

Add new group to workspace

Add a group to a given workspace:

Add-PowerBIWorkspaceUser -WorkspaceId 3244f1c1-01cf-457f-9383-6035e4950fdc -Identifier "ddc3ecc2-e17e-4353-9b42-964b55500e0f" -AccessRight Contributor -PrincipalType Group

Remove a user from a given workspace

Remove user's permissions from a given workspace:

Remove-PowerBIWorkspaceUser -Scope Organization -Id 3244f1c1-01cf-457f-9383-6035e4950fdc -UserEmailAddress john@contoso.com

Get workspace migration status

Get Power BI workspace migration status:

Get-PowerBIWorkspaceMigrationStatus -Id 038f9a64-1fcd-42f2-957a-13a63b3d3235

Restore workspace

To view deleted workspaces as a tenant administrator:

Get-PowerBIWorkspace -Scope Organization -Deleted -All

Restores a deleted workspace:

Restore-PowerBIWorkspace -Id "3244f1c1-01cf-457f-9383-6035e4950fdc" -RestoredName "TestWorkspace" -AdminEmailAddress "[email protected]"

Recover orphaned workspaces

A workspace becomes orphaned when it has no assigned administrators. If you are a tenant administrator, run the following to view all orphaned workspaces:

Get-PowerBIWorkspace -Scope Organization -Orphaned -All

To correct this issue, use:

Add-PowerBIWorkspaceUser -Scope Organization -Id f2a0fae5-1c37-4ee6-97da-c9d31851fe17 -UserPrincipalName '[email protected]' -AccessRight Admin

Get reports

Get all reports for the user:

Get-PowerBIReport

If you are a tenant administrator, you can view all reports in your tenant by using assigning -Scope Organization:

Get-PowerBIReport -Scope Organization

Get dashboards

Get dashboards for the user:

Get-PowerBIDashboard

If you are a tenant administrator, you can view all dashboards in your tenant by adding -Scope Organization:

Get-PowerBIDashboard -Scope Organization

Get tiles

Get tiles within a dashboard:

Get-PowerBITile -DashboardId 9a58d5e5-61bc-447c-86c4-e221128b1c99

Get imports

Get Power BI imports:

Get-PowerBIImport

Create report

Create a report in Power BI by uploading a *.pbix file:

New-PowerBIReport -Path .\newReport.pbix -Name 'New Report'

By default, the report is placed in the user's My Workspace. To place in a different workspace, use the -WorkspaceId or -Workspace parameters:

New-PowerBIReport -Path .\newReport.pbix -Name 'New Report' -WorkspaceId f95755a1-950c-46bd-a912-5aab4012a06d

Export report

Export a Power BI report to *.pbix file:

Export-PowerBIReport -Id b48c088c-6f4e-4b7a-b015-d844ab534b2a -OutFile .\exportedReport.pbix

If the workspace exists outside the My Workspace, export with the WorkspaceId or -Workspace parameter:

Export-PowerBIReport -Id b48c088c-6f4e-4b7a-b015-d844ab534b2a -OutFile .\exportedReport.pbix -WorkspaceId 3bdd9735-0ab5-4f21-bd5d-87e7f1d7fb84

Get datasets

Get Power BI datasets:

Get-PowerBIDataset

Update dataset storage mode

Set Power BI dataset to use Premium Files for storage mode:

Set-PowerBIDataset -Id 038f9a64-1fcd-42f2-957a-13a63b3d3235 -TargetStorageMode PremiumFiles

Get datasources

Get Power BI datasources for a dataset:

Get-PowerBIDatasource -DatasetId 65d7d7e5-8af0-4e94-b20b-50a882ae15e1

Get tables

Get Power BI tables contained within a dataset:

Get-PowerBITable -DatasetId 65d7d7e5-8af0-4e94-b20b-50a882ae15e1

Call the Power BI Rest API

For Power BI API that lacks corresponding cmdlets, you can reuse the authenticated session from Connect-PowerBIServiceAccount to make custom REST requests:

Invoke-PowerBIRestMethod -Url 'reports/4eb4c303-d5ac-4a2d-bf1e-39b35075d983/Clone' -Method Post -Body ([pscustomobject]@{name='Cloned report'; targetModelId='adf823b5-a0de-4b9f-bcce-b17d774d2961'; targetWorkspaceId='45ee15a7-0e8e-45b0-8111-ea304ada8d7d'} | ConvertTo-Json -Depth 2 -Compress)

If you want to use the authenticated session outside of PowerShell, get the access token by using:

Get-PowerBIAccessToken -AsString

Troubleshooting errors

To get more information about an error returned back from the cmdlets, use:

Resolve-PowerBIError -Last

This information can be useful for opening support tickets for Power BI.

Issues and feedback

If you find any bugs or would like to see certain functionality implemented for the PowerShell Cmdlets for Power BI, please file an issue here. If the issue is an error returned from the cmdlets, add detail from Resolve-PowerBIError to the issue.

If your issue is broader than just the PowerShell cmdlets, please submit your feedback to the Power BI Community or the official Power BI Support site.

We track our roadmap of planned features in ROADMAP.md.

Reporting security issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at [email protected].

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

More information about contributing can be found in this CONTRIBUTING guide.

powerbi-powershell's People

Contributors

carmbell avatar cattiecat avatar cedarbaum avatar codecyclone avatar dependabot[bot] avatar inthemedium avatar jayanth2830 avatar kayunkroth avatar kenakamu avatar lankaapura avatar marinafusterms avatar mgblythe avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar nandemoii avatar saibotchu avatar shpittam avatar speshoria avatar toymsft avatar yiqyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powerbi-powershell's Issues

Need support for -All parameter

The Azure AD cmdlets, such as Get-AzureADUser (https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureaduser), support a Boolean -All parameter. The Power BI cmdlets should support the same so that tenants with large numbers of artifacts donโ€™t pull down the full list (which can take a long time) unintentionally.
If true, return all items. If false, return the number of objects specified by the -First (top) parameter or 25 items if -First was not specified.

Example to return all workspaces in a tenant: Get-PowerBIWorkspace -All $true

Invoke-PowerBIRestMethod fails with Service Principal

Invoke-PowerBIRestMethod does not function when being called from a Service Principal. I have configured the service principal in the Azure tenant with the required API permissions, but the service account can't call the Invoke-PowerBIRestMethod. The value returned says it's not authorized even though it has permissions. I also tried this with Get-PowerBIReport -Scope Organization and Invoke-RestMethod with no success.

Example script:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$tenantId = "#####"
$AppId = "#####"
$PasswordClearText = "######"

$PW = ConvertTo-SecureString -String $PasswordClearText -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $AppId, $PW

Import-Module -name MicrosoftPowerBIMgmt

$Account = Connect-PowerBIServiceAccount -Credential $Credential -Tenant $tenantId -ServicePrincipal
if(!$Account) {
Throw "Could not connect to Power BI service account."
}

$Reportsresponse = Invoke-PowerBIRestMethod -Url 'reports' -Method Get
if(!$Reportsresponse){
Resolve-PowerBIError
}

$Reportsresponse.value | Out-Host

Disconnect-PowerBIServiceAccount

Message : Response status code does not indicate success: 401 (Unauthorized).
StackTrace : at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.d__31.MoveNext()
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Invoke-PowerBIRestMethod}
Line : $Reportsresponse = Invoke-PowerBIRestMethod -Url 'reports' -Method Get

Position : - Doc\PowerShell\Azure Authentication Test - Az.ps1:46 char:20
+ ... Reportsresponse = Invoke-PowerBIRestMethod -Url 'reports' -Method Get
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 1

Application ID and Key

Hi folks, it's posible to use Azure Application with key instead of use PBI Login and Password?

Connect-PowerBIServiceAccount picks the wrong identity even when told the right one

So I'm using Connect-PowerBIServiceAccount to connect before querying the service for dataset data.

I have two accounts on the same tenant - jsnape and jsnape01 (the latter is an admin account that is used elsewhere in Azure).

When I call Connect-PowerBIServiceAccount it pops up the AD dialog and gives me the choice of account. I select the jsnape account and it always returns:

Environment : Public
TenantId    : xxxxxxx-yyyy-zzzz-a46c-00000000
UserName    : jsnape01@vvvvvvvvvv.com

i.e. it always uses my 01 account.

I have tried the following with no success to get it to pick the right account:

  1. Logged out of all browers, cleaned cache and close windows
  2. Removed the 01 account from the AD dialog before logging in
  3. Closed PowerShell
  4. Logout of Windows

How can I make it use the right account?

More datasets reported in Personal Workspace than actually exist

Hi,

I ran a script in my company's tenant to extract all workspaces, for each workspaces all datasets and then count the number of source types e.g. file, sql server to better understand what data our company is looking at.

I'm seeing some strange behavior though for Personal workspaces. I can see for example that I have a lot of dataset_id linked to my personal workspace even though in reality I only have one dataset. Thus I'm trying to understand the behavior of the commands here. I've listed it down below in a more structured format

Background:

  • I have one dataset in my personal workspace
  • I don't have any datasets shared with me
  • I am a member of several app workspaces
  • I am also using some Apps

I'm using the following command:
Get-PowerBIDataset -scope Organization -WorkspaceId ... logged in as a PowerBI admin

Expectation: to only see the dataset that I have in my personal workspace
Reality: I am seeing datasets that are in Apps that I use and in App workspace I am a member off

Questions

  • Do datasets in app workspaces you are a member off automatically appear when you query your personal workspace?
  • Do datasets in apps you use automatically appear when you query your personal workspace?

Permissions needed for Service Principal

Is there a guide on how to create an Azure AD registered app (aka Service Principal) that has permissions to use these powershell commands?

I created an 'App Registration' in our Azure Active Directory.

I had our global admin grant it the 'Read and write all content in tenant' and 'View all content in tenant' permissions

I login successfully:

$tenantId = '<redacted>'
$applicationId = '<redacted>'
$key = '<redacted>'

$secureKey = ConvertTo-Securestring -String $key -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId,$secureKey

Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -Tenant $tenantId

Environment : Public
TenantId    : 
ClientId    : <redacted>
Password    : ********

But I get an unauthorized error from any of the commands:

PS> Get-PowerBIReport
Get-PowerBIReport : Operation returned an invalid status code 'Unauthorized'

Failure trying to import-module

On a windows 10 machine:

Error:
PS H:> Import-Module -Name MicrosoftPowerBIMgmt
Import-Module : Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Reference assemblies should not be loaded for execution.
They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
At line:1 char:1

  • Import-Module -Name MicrosoftPowerBIMgmt
  •   + CategoryInfo          : NotSpecified: (:) [Import-Module], BadImageFormatException
      + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.ImportModuleCommand
    
    
    

$PSVERSIONTABLE

Name Value


PSVersion 5.1.14393.2363
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2363
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Login to PBI as a different user

Hi all, I have two Azure accounts, one is my regular account and the other is an admin account. When I try Login-PowerBI a popup appears, I fill in the admin account username and click next, then however I'm getting automatically signed to my regular account

I'm sure this has something to do with the way that single sign on is configured in my organisation, however I'm stuck trying to find a way around it. Any ideas?

Get-PowerBIReport -Scope Organization and deleted reports

When I run Get-PowerBIReport -Scope Organization I get deleted reports but there is no way to filter them out (even afterwards, as there is no "active" property present). On the other hand, if the scope is Individual, only active reports are returned. Is there a way to exclude deleted reports when the scope is Organization?

Add cmdlet to get App information

A cmdlet to get information about the App published from a Workspace.

  • Access (users and groups)
  • Content in the App (dashboards, reports, data sets, workbooks, etc.)

Could not load type 'System.Runtime.InteropServices.OSPlatform

Running PowerShell 5.1 on Windows 7 running .Net received following error:

Connect-PowerBIServiceAccount : Could not load type 'System.Runtime.InteropServices.OSPlatform' from assembly 'netstandard, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'.
At line:1 char:1

  • Connect-PowerBIServiceAccount
  •   + CategoryInfo          : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], TypeLoadException
      + FullyQualifiedErrorId : Could not load type 'System.Runtime.InteropServices.OSPlatform' from assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyTok 
     en=cc7b13ffcd2ddd51'.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBIServiceAccount
    

Unable to Connect with Power BI Service using PowerShell

I have installed PowerShell for Power BI using following Code.
Install-Module -Name MicrosoftPowerBIMgmt
It is installed successfully.
2018-08-08_9-55-31
Now, I used following code-snippet to connect with Power BI Service.
Login-PowerBI
When I executed the code it shows me an error like:
Login-PowerBI : The 'Login-PowerBI' command was found in the module 'MicrosoftPowerBIMgmt.Profile', but the module could not be loaded. For more information, run 'Import-Module MicrosoftPowerBIMgmt.Profile'. At line:1 char:1 + Login-PowerBI`

+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Login-PowerBISmiley Frustratedtring) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule`
![screenshot_4](https://user-images.githubusercontent.com/41663430/43937993-d5198450-9c7e-11e8-95ff-562315ef29f3.png)
I have also tried to import  module MicrosoftPowerBIMgmt.Profile using following code:

`Import-Module MicrosoftPowerBIMgmt.Profile`

It shows me following error:

Import-Module : Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, 
PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Reference assemblies should not be loaded for 
execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
At line:1 char:1
+ Import-Module MicrosoftPowerBIMgmt.Profile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Smiley Happy [Import-Module], BadImageFormatException
    + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.ImportModuleCommand

Below is a screenshot for the same.
untitled

Same Question is posted here as well.
https://community.powerbi.com/t5/Developer/Unable-to-Connect-with-Power-BI-Service-using-PowerShell/m-p/484963#M14886

Add-PowerBIDataSet : Unable to cast object of type 'Microsoft.PowerBI.Common.Api.Datasets.Column' to type 'Microsoft.PowerBI.Api.V2.Models.Column'.

I have successfully connected to my PowerBI instance using Connect-PowerBIServiceAccount and am trying to follow the Get-Help example for the Add-PowerBIDataSet cmdlet.

I am getting the following error.

$>$col1 = New-PowerBIColumn -Name SampleName -DataType String
$>$table1 = New-PowerBITable -Name SampleTable1 -Columns $col1
$>$dataset = New-PowerBIDataSet -Name SampleDataSet -Tables $table1
$>Add-PowerBIDataSet -DataSet $dataset
Add-PowerBIDataSet : Unable to cast object of type 'Microsoft.PowerBI.Common.Api.Datasets.Column' to type 'Microsoft.PowerBI.Api.V2.Models.Column'.
At line:1 char:1
+ Add-PowerBIDataSet -DataSet $dataset
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...dPowerBIDataset:AddPowerBIDataset) [Add-PowerBIDataset], InvalidCastException
    + FullyQualifiedErrorId : Unable to cast object of type 'Microsoft.PowerBI.Common.Api.Datasets.Column' to type 'Microsoft.PowerBI.Api.V2.Models.Column'.,Microsoft.PowerBI.Commands.Data.AddPowerB
   IDataset

Cmdlets can't be loaded on a network share

If the cmdlets are installed on a network share (and share not mounted as a drive), the cmdlets error with "Unable to find setting configuration".

The file name is missing the share name (full UNC path), such as \Users\name\modules\โ€ฆ.

Fix is in PowerBISettings.cs, there may be other areas where network paths are not supported.

Get-PowerBIWorkspace : Attempted to access an element as a type incompatible with the array.

When I run the example code from https://docs.microsoft.com/en-us/powershell/power-bi/overview?view=powerbi-ps

Login-PowerBIServiceAccount
Get-PowerBIWorkspace

I get the error

Get-PowerBIWorkspace : Attempted to access an element as a type incompatible with the array.
At line:2 char:1
+ Get-PowerBIWorkspace
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...owerBIWorkspace:GetPowerBIWorkspace) [Get-PowerBIWorkspace], ArrayTypeMismatchException
    + FullyQualifiedErrorId : Attempted to access an element as a type incompatible with the array.,Microsoft.PowerBI.Commands.Workspaces.GetPowerBIWorkspace

There was a similar issue (#60) that was marked as closed with a note to update .NET but I am running the current version and still get this erro

User Authentication Without Prompt

I currently have a user account set up in AzureAD with a PowerBI Pro licence assigned exclusivly for the use of embedding reports within my application on behalf of users who do not have PowerBI Pro licences as described here.

I would like to use the credentials of this existing user account to authenticate with the PowerShell libriaries to build some utilities to manage the reports in this application but it appears that the only way to authenticate as a user is via a pop up which is not ideal for my use case.

Is there currently any way to authenticate with the PowerBI Powershell libraries without this prompt? Ideally I would like to pass in a PSCredential made up of the user account's Username and Password along with the clientId of the registered application in AzureAD to recieve the access token.

I have found an example which manually imports Microsoft.IdentityModel.Clients.ActiveDirectory in order to authenticate using username/password/clientId but this feels like a messy workaround.

Is there any plan to add user authentication in this way to the official PowerBI PowerShell cmdlets?

Thanks.

Pull gateway configuration and datasources

One major hurdle we have is an ability to central manage and monitor gateways tied to our org. while the latest subset of commandlets are a nice step in allowing org admins to view datasets, etc. still appears that security and management is taken a back seat to product. I was originally told that gateway management/monitoring was supposed to be released in Q2 of 2018 and here we are half way through Q3. I really want to release gateway to users however with the current subset of available powershell commands and auditing, I can not at this time. while the current gateway and powerbi empowers the users, it also fosters a mindset of shadow IT which is a bad thing in large IT enterprises. Gateways provide a proxy for users to share information, and without the ability to query what is shared or configured sensitive data could be inadvertently leaked to unauthorized individuals

Cannot make it work in powershell 5.1

Maybe, I'm not getting it correctly, so feel free to blame me, but...

Install-Module -name MicrosoftPowerBIMgmt # works like a charm

Import-Module -name MicrosoftPowerBIMgmt or just simply running Connect-PowerBIServiceAccount or anything else ends up with:
_Import-Module : Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT:
0x80131058)
At line:1 char:1

  • Import-Module -Name MicrosoftPowerBIMgmt.Profile
  •   + CategoryInfo          : NotSpecified: (:) [Import-Module], BadImageFormatException
      + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.ImportModuleCommand_
    
    

get-host
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse
returns:

_Name : Windows PowerShell ISE Host
Version : 5.1.15063.1088
InstanceId : 1026cdab-d162-42ee-839f-ab276e926a30
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

PSChildName : v2.0.50727
Version : 2.0.50727.4927
Release :
PSChildName : v3.0
Version : 3.0.30729.4926
Release :
PSChildName : Windows Communication Foundation
Version : 3.0.4506.4926
Release :
PSChildName : Windows Presentation Foundation
Version : 3.0.6920.4902
Release :
PSChildName : v3.5
Version : 3.5.30729.4926
Release :
PSChildName : Client
Version : 4.7.02046
Release : 460798
PSChildName : Full
Version : 4.7.02046
Release : 460798
PSChildName : Client
Version : 4.0.0.0
Release :_

I've tried installing dotnet core 2.1, 2.1 SDK included the path to the netstandard.dll in path, with no luck.

I must be missing something.

Oh, I was kind of missing something "[Future release]". So it works in powershell core 6.0.2 (but no luck in 5.1.15063.1088), maybe the powerbi-powershell is only for powershell core 6.

Thanks

Add-PowerBIWorkspaceUser BadRequest when AccessRight is Member or Contributor

Hello,

When I try to add a user to a workspace with the command:
Add-PowerBIWorkspaceUser -Id [id] -UserEmailAddress [emailaddress] -AccessRight Member
or:
Add-PowerBIWorkspaceUser -Id [id] -UserEmailAddress [emailaddress] -AccessRight Contributor

I get the following error:

Add-PowerBIWorkspaceUser : Operation returned an invalid status code 'BadRequest'
At line:1 char:1

  • Add-PowerBIWorkspaceUser -Id ..... -Us ...
  •   + CategoryInfo          : WriteError: (Microsoft.Power...BIWorkspaceUser:AddPowerBIWorkspaceUser) [Add-PowerBIWorkspaceUser], HttpOperationException
      + FullyQualifiedErrorId : Operation returned an invalid status code 'BadRequest',Microsoft.PowerBI.Commands.Workspaces.AddPowerBIWorkspaceUser
    
    

The command works fine when I add the user as Admin. But I don't want the user to be Admin, I want to set the AccessRight to Member.

What is going wrong?

Thanks,

Marc

Export-PowerBIReport Is not working as admin

I'm running Export-PowerBIReport as global admin and I'm receiving an 'Unauthorized' error (full error below) for reports in workspaces I am not assigned or other user's personal workspaces. I can list all the reports in all the personal workspaces of other people though. We are in the middle of the transition process to GCC from the public tenant, it would be nice to export all of our user's content from the public tenant before we lose access.

RequestId : cc691c42-e5fa-4919-976f-846d8a1acf7c
Response : Unauthorized (401): {"error":{"code":"PowerBINotAuthorizedException","pbi.error":{"code":"PowerBINotAuthorizedException","parameters":{},"details":[],"exceptionCulprit":1}}}
PowerBIErrorInfo :
ResponseDate : Thu, 09 Aug 2018 07:13:34 GMT
RequestMethod : GET
RequestUri : https://api.powerbi.com/v1.0/myorg/reports/46590729-0131-46a5-b702-bde21ed9033e/Export
InvocationInfo : {Export-PowerBIReport}
Line : Get-PowerBIReport -WorkspaceId 'df5e1412-b279-4955-988e-6917af3d02ac' -Scope Organization | %{Export-PowerBIReport -Id $.id -OutFile D:\ner.pbix }
Position : At line:1 char:96
+ ... rganization | %{Export-PowerBIReport -Id $
.id -OutFile D:\ner.pbix }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace : at Microsoft.PowerBI.Api.V2.Reports.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.V2.ReportsExtensions.d__29.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.V2.ReportsExtensions.ExportReport(IReports operations, String reportKey)
at Microsoft.PowerBI.Common.Api.Reports.ReportsClient.ExportReport(Guid reportId, Nullable`1 workspaceId)
at Microsoft.PowerBI.Commands.Reports.ExportPowerBIReport.ExecuteCmdlet()
at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.ProcessRecord()
HistoryId : 173

Export-PowerBIReport returns Unauthorized

I am the admin for a Workspace (original workspace paradigm, not new one) and I cannot run the Export-PowerBIReport cmdlet. It keeps returning Unauthorized. I also have the Power BI Administrator role and am the owner of this particular O365 group. I am also a Global Administrator in O365.

I can run all the other Get cmdlets for the entire Organization. It's just Export-PowerBIReport which is giving me problems. I've assigned all the rights I know about. Let me know if there's anything else I can do to troubleshoot the issue.

image

MicrosoftPowerBIMgmt.Profile source location is not valid

I'm trying to install the MicrosoftPowerBIMgmt module. I run the following command:

Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser

I received the following message:
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/MicrosoftPowerBIMgmt.Profile/1.0.326' is not valid. PackageManagement\Install-Package : Package 'MicrosoftPowerBIMgmt.Profile' failed to download.

Any ideas whats happening?

Add tests for new cmdlets

Need to add tests for:

  • Get-PowerBIDataset
  • Get-PowerBIDatasource
  • Export-PowerBIReport
  • Get-PowerBITile
  • Get-PowerBIImport
  • Get-PowerBIReport with -Scope Organization
  • Invoke-PowerBIRestMethod
  • Get-PowerBIAccessToken

-Scope Organization supported for all Workspaces

I'm a Power BI Service Admin (via AAD Priv ID management), and I tried using this command to add a user to an orphaned workspace, but got hit with the following error:

WARNING: Only preview workspaces are supported when -Scope Organization is specified

Add-PowerBIWorkspaceUser : Operation returned an invalid status code 'InternalServerError'

At C:\Users\<username>\Desktop\<script>.ps1:7 char:1

+ Add-PowerBIWorkspaceUser -Scope Organization -Id x#xx####-#x##-###x-# ...

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

  + CategoryInfo          : WriteError: (Microsoft.Power...BIWorkspaceUser:AddPowerBIWorkspaceUser) [Add-PowerBIWorkspaceUser], HttpOperationException

    + FullyQualifiedErrorId : Operation returned an invalid status code 'InternalServerError',Microsoft.PowerBI.Commands.Workspaces.AddPowerBIWorkspaceUser

Any idea when non-preview Workspaces will be supported? This would be an invaluable tool for saving my users lots of rework and cleaning up our Cloud Service tenant.

Add Workspace User with -Scope Organization no longer working

Hello,

Recently the new preview workspaces were announced for Power BI (8/9/2018). Before this I was able to use -Scope Organization for Workspace Cmdlets as I am an Admin in Power BI.

However, when trying to use Add-PowerBIWorkspaceUser -Scope Organization I get the following Warning:

WARNING: Only preview workspaces are supported when -Scope Organization is specified

Then the full Error Log:

Add-PowerBIWorkspaceUser : Operation returned an invalid status code 'InternalServerError'
At line:1 char:1
+ Add-PowerBIWorkspaceUser -Scope Organization -Id xxxxxxxxxxxx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...BIWorkspaceUser:AddPowerBIWorkspaceUser) [Add-PowerBIWorkspaceUser], HttpOperationException
    + FullyQualifiedErrorId : Operation returned an invalid status code 'InternalServerError',Microsoft.PowerBI.Commands.Workspaces.AddPowerBIWorkspaceUser
 

I am not a member of the Workspace so I have to use the Scope command.

Refresh DataSet

Hi All,

I was able to connect and to retrieve DataSets. Is there a method/way to trigger a refresh of an existing dataset? (like the "Refresh now"-Button)

Thanks

Connect-PowerBIServiceAccount: issue connecting

I am trying connecting in PS using the cmd:
Connect-PowerBIServiceAccount -Environment Public -Credential (Get-Credential) -ServicePrincipal

I tried with my account, PowerBI Admin for our tenant and I am getting error.

When looking at the details, it's like the domain part @domainname.com has got removed.

Here are the details:
PS C:\WINDOWS\system32> Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePrincipal
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Connect-PowerBIServiceAccount : One or more errors occurred.
At line:1 char:1

  • Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePr ...
  •   + CategoryInfo          : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-PowerBIServiceAccount], AggregateException
      + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.ConnectPowerBIServiceAccount
    
    

PS C:\WINDOWS\system32> Resolve-PowerBIError -Last

HistoryId: 43

Message : AADSTS70001: Application with identifier 'adm-blabla' was not found in the directory analysis.windows.net
Trace ID: 2dd34999-9fd3-4521-863b-22e8ac011c00
Correlation ID: 36c2570a-5452-4ee9-bafd-23bd11409a57
Timestamp: 2018-09-10 14:49:34Z
StackTrace : at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Http.AdalHttpClient.d__221.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Http.AdalHttpClient.<GetResponseAsync>d__211.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.d__72.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.d__69.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.d__59.MoveNext()
Exception : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException
InvocationInfo : {Connect-PowerBIServiceAccount}
Line : Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePrincipal
Position : At line:1 char:1
+ Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 43

Message : Response status code does not indicate success: 400 (BadRequest).
StackTrace :
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Connect-PowerBIServiceAccount}
Line : Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePrincipal
Position : At line:1 char:1
+ Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 43

Message : {"error":"unauthorized_client","error_description":"AADSTS70001: Application with identifier 'adm-blabla' was not found in the directory analysis.windows.net\r\nTrace ID:
2dd34999-9fd3-4521-863b-22e8ac011c00\r\nCorrelation ID: 36c2570a-5452-4ee9-bafd-23bd11409a57\r\nTimestamp: 2018-09-10
14:49:34Z","error_codes":[70001],"timestamp":"2018-09-10
14:49:34Z","trace_id":"2dd34999-9fd3-4521-863b-22e8ac011c00","correlation_id":"36c2570a-5452-4ee9-bafd-23bd11409a57"}: Unknown error
StackTrace :
Exception : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException
InvocationInfo : {Connect-PowerBIServiceAccount}
Line : Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePrincipal
Position : At line:1 char:1
+ Connect-PowerBIServiceAccount -Credential (Get-Credential) -ServicePr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 43

Support Get-Credential without requiring a ServicePrincipal

Connect-AzureAD and Connect-MsolService support the -Credential parameter without any additional ServicePrincipal requirements. Login-PowerBI (Connect-PowerBIServiceAccount) should do the same.
This should work:
$cred = Get-Credential
Login-PowerBI -Credential $cred

Update Get-PowerBIDataset for user API

Doc update for Get-PowerBIDataset for user API
User API for datasets only returns the datasets from "My Workspace" unless a workspace ID is specified with -WorkspaceId

Unable to call imports endpoint

I am trying to automate uploading a .pbix file to Power BI. It looks like I need to use the imports API.

https://docs.microsoft.com/en-us/rest/api/power-bi/imports/postimport

The Invoke-PowerBIRestMethod doesn't support supplying a ContentType, which needs to be 'multipart/form-data'.

I have tried to implement Import-PowerBIImport with this function:

function Invoke-PowerBIImport {
    param
    (
        [string]$Path,
        [string]$DatasetDisplayName,
        [string]$GroupId
    )

    $file = Get-Item $Path -ErrorAction SilentlyContinue
    if (-not $file) {
        throw "Unable to find file $Path"
    }

    $fileBytes = [System.IO.File]::ReadAllBytes($file.FullName)
    $encoding = [System.Text.Encoding]::GetEncoding("iso-8859-1")
    $boundary = [guid]::NewGuid().ToString()

    $template = @'
--{0}
Content-Disposition: form-data; name="fileData"; filename="{1}"
Content-Type: application/octet-stream

{2}
--{0}--

'@
    $body = $template -f $boundary, $File.Name, $encoding.GetString($fileBytes)

    $headers = Get-PowerBIAccessToken
    $headers.'Content-Type' = "multipart/form-data; boundary=$boundary"

    if ($GroupId) {
        $url = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/imports&datasetDisplayName=$DatasetDisplayName&nameConflict=CreateOrOverwrite"
    }
    else {
        $url = "https://api.powerbi.com/v1.0/myorg/imports&datasetDisplayName=$DatasetDisplayName&nameConflict=CreateOrOverwrite"
    }

    $response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body
    $response
}

But this results in "The requested resource does not support http method 'POST'."  

Do you know what is wrong with this?




Get-PowerBIDataset return workspace

Get-PowerBIDataset does not return a workspace field. The only approach it's execute get-powerbiworkspace and do a foreach on each workspace?

Get-PowerBIDataset crashes for personal workspaces

When I use Get-PowerBIDataset and pass the GUID of a personal workspace as parameter, it crashes with

Get-PowerBIDataset : Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

even though the parameter is well-formed. However, it works fine with the GUIDs of "regular" workspaces.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.