Forum Discussion

AbhijitSarkar's avatar
AbhijitSarkar
Copper Contributor
May 26, 2021

"get-PowerBiWorkspace" giving error like 'incompatible with the array'

Hi,

"Get-PowerBiWorkspace " is giving error like below. I tried to execute in VS-Code, ISE and Powershell -Noprofile, but no luck. Please help me to resolve this. 

get-PowerBiworkspace : Attempted to access an element as a type incompatible with the array.
At line:1 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

 

I am using PowerShell 5.1 .Below is list of modules are present in my machine.

 

Newtonsoft module::

MDStreamVersion : 131072
FullyQualifiedName : C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.1.2\PreloadAssemblies\Newtonsoft.Json.12.0.3.dll
ModuleVersionId : 2676a2da-6edc-420e-890e-d28aa4572ee5
MetadataToken : 1
ScopeName : Newtonsoft.Json.dll
Name : Newtonsoft.Json.12.0.3.dll
Assembly : Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
CustomAttributes : {}
ModuleHandle : System.ModuleHandle

 

MicrosoftPowerBIMgmt module::

 

I have uninstalled MicrosoftPowerBIMgmt and installed it again.

 

  • JudyO72's avatar
    JudyO72
    Copper Contributor

    AbhijitSarkar A Microsoft technician provided this code to us to run in Azure Automation. This worked.  This runs in powershell 5.1 HybridWorker.  make sure the Hybrid worker has all the powerbi modules.  Hope this helps.

    if ($($env:computerName) -eq "Client") {"Runbook running on Azure Client sandbox"} else {"Runbook running on " + $env:computerName}

    Write-Output "Parent runbook"
    [Newtonsoft.Json.JsonConvert].Module
    $cred = Get-AutomationPSCredential -Name 'TheName'
    #POWERBI MODULE SECTION
    # PowerShell background Job for PowerBI module to avoid modules incompatibility
    Write-Warning "Starting PowerShell background for PowerBI module"
    $job = Start-Job -ScriptBlock {
    Param($jobResults)

    Write-Output "Importing Orchestrator AssetManagement Cmdlets module"
    Import-Module Orchestrator.AssetManagement.Cmdlets

    #Connection and your script

    Connect-PowerBIServiceAccount -Credential $using:Cred

    Get-PowerBIWorkspace -Scope Organization -All

    #End of your script

    Write-Output "Background job Newtonsoft Version check 1"
    [Newtonsoft.Json.JsonConvert].module
    } -ArgumentList (,$Results)

    Write-Output "Waiting for Job to finish"
    Wait-Job $job
    Write-Output "Retrieving Job output"
    Receive-Job -ID $job.id -keep

Resources