cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoshT
Advocate I
Advocate I

PowerShell AzureAD cmdlets incompatible with MicrosoftPowerBIMgmt - BUG

I'm attempting to automate assignment of AzureAD groups as permission containers against workspaces using PowerShell. This is currently not possible because of two issues preventing the use of the AzureAD and MicrosoftPowerBIMgmt modules in the same script.

Firstly, Power BI cmdlets don't work in PowerShell 5.1 when the AzureAD module is loaded into a session because of an under the hood issue that has been reported several times and hasn't been fixed in at least 2 years: https://github.com/Microsoft/powerbi-powershell/issues/60. This issue (error returned 'attempted to access an element as a type incompatible with the array') can be replicated by running the below:

 

Import-Module MicrosoftPowerBIMgmt
Import-Module AzureAD
Login-PowerBI
Get-PowerBIWorkspace -Name [any valid workspace name in tenant]

Get-PowerBIWorkspace : Attempted to access an element as a type incompatible with the array.
At line:4 char:1
+ Get-PowerBIWorkspace -Name "grp-ITSBI Product Team-Dev"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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

 

The only workaround I've seen suggested for this is to use PowerShell Core (I'm currently running PowerShell 7.1.2). Unfortunately this runs into this issue: https://github.com/PowerShell/PowerShell/issues/10473, which is caused by AzureAD not supporting .NET Core and therefore conflicting with libraries when attempting to connect to Azure:

 

Import-Module AzureAD
Connect-AzureAD

Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.)
Connect-AzureAD: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

 

There has been a workaround suggested here https://github.com/PowerShell/PowerShell/issues/11564 to use the -UseWindowsPowerShell switch on the import-module command for compatibility outside of .NET Core. Unfortunately this just means that you get the same error when trying to connect to the Power BI service instead.

Is anyone aware of any workaround that might be available to allow concurrent access to both the Azure tenant and Power BI service, or better yet, a channel for escalating this or even a fix for this issue? Given how tightly linked Power BI is to Azure, I would expect this to be functioning properly to make Power BI manageable as a service

4 REPLIES 4
pvuppala
Helper II
Helper II

Hi Josh, PLEASE tell me you found a workaround with this issue? Same exact issue here !!!

 

Please let me know.

Sadly not. I posted on this issue page (https://github.com/microsoft/powerbi-powershell/issues/261) a while back and the response, despite multiple people showing the bug, was a resounding 'don't care'. They've said the Azure modules will support PowerShell Core sometime in 2022, which will resolve the issue, but last time I checked this hasn't been done (great stuff leaving a terminal bug open a whole year!)

 

I hear Gartner gave Power BI a bit of a kicking in its magic quadrant this year for Power BI's surprisingly atrocious support for administration features and that Microsoft have paid attention to this and are working on making things more manageable. Have to say I have not had a good time on this side of things, and the APIs which are frequently touted as a solution for feature gaps, in a lot of cases have these kind of breaking issues that makes them unusable.

JoshT
Advocate I
Advocate I

Hi @v-lionel-msft ,

That's what I was trying, so still getting the same error regardless of opening up a new session. According to comments on the github pages and a number of other places this is caused by a conflict in the Newtonsoft.Json DLLs loaded into the session. Interestingly, I have the same versions of both modules as you've shown here, which leads me to think that the conflicting DLL version has turned up through some other module or software on the machine.

 

This is a known issue and doesn't appear to be fixable by developers so I'm quite surprised MS hasn't picked it up for such a long time. According to other sources, the AzureAD team is a bit of a black box so not much hope for .NET Core support in the near future - it looks like it can only be fixed on the Power BI side

v-lionel-msft
Community Support
Community Support

Hi @JoshT ,

 

Is this what you want?

v-lionel-msft_0-1614231434748.png

v-lionel-msft_1-1614232173540.png

 

You may need to reopen a session.

v-lionel-msft_4-1614233664218.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 25

Ted's Dev Camp - August 25, 2022

Watch Session 25 of Ted's Dev Camp.

Top Solution Authors