cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoshT
Frequent Visitor

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

2 REPLIES 2
JoshT
Frequent Visitor

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

April Update

Check it Out!

Click here to read more about the April 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Kudoed Authors