PowerBI Query - Trying to list workspaces and users

I made several attempts to list the active workspaces and their users in a row-style output. I have the following query:

$ActiveWorkspaces = Get-PowerBIWorkspace -Scope Organization -All | Where {($_.Type -eq "Workspace") -and ($_.State -eq "Active")} 

When you run the query, there are several workspaces listed with their properties and then the Users property has subproperties of AccessRight and UserPrincipalName. I’d like to line up the workspace name and user properties.

Any suggestions?

Thanks,

Frank

 

I forgot to add this part:

$ActiveWorkspaces | Select-Object name, users

This returns the users grouped with the workspace name:

workspace1 {user1@, user2@, user3@}

workspace2 {user1@, user2@}

I would like to list the workspace and user on separate lines?

Hmmm … I’m not quite sure if I got what you mean … did you try Format-List?

Hi, sorry. I should’ve been clearer. I want the output to look like the following:

workspace1 user1

workspace1 user2

workspace1 user3

workspace2 user1

workspace2 user2

I want to list the workspace and user on their own lines.

Hope this helps!

Ah … you could use nested loops to achieve this …

$ActiveWorkspaces | 
    ForEach-Object {
        $Workspace = $_.name
        foreach ($User in $_.Users) {
            [PSCustomObject]@{
                Workspace = $Workspace
                User      = $User
            }
        }
    }

… of course … untested :wink:

That’s pretty much what I need, but the Users seemed to be a subproperty of the main object:

Users :
AccessRight UserPrincipalName


Admin user1

If you run just the $activeworkspaces variable without the loop, it returns it as ‘Users’ with its own sub-properties of ‘AccessRight’ and ‘UserPrincipalName’. The ‘UserPrincipalName’ is what I need to be listed with the workspace name.

 

 

 

Hmmm … so you are lucky with it or do you need something more? Did you get what you need, finally? You reply is not quite clear about that.

If you need a subproperty of the variable $User with the the UserPrincipalName you simply use the “dot notation” …

$User.UserPrincipalName

That was it! Thx for all of your help!