|
| 1 | +function Get-FabricWorkspaceUser |
| 2 | +{ |
| 3 | + <# |
| 4 | +.SYNOPSIS |
| 5 | +Retrieves the user(s) of a workspace. |
| 6 | +
|
| 7 | +.DESCRIPTION |
| 8 | +The Get-FabricWorkspaceUser function retrieves the details of the users of a workspace. |
| 9 | +
|
| 10 | +.PARAMETER WorkspaceId |
| 11 | +The ID of the workspace. This is a mandatory parameter if Workspace is not provided. |
| 12 | +
|
| 13 | +.PARAMETER Workspace |
| 14 | +The workspace object. This normally comes from the Get-FabricWorkspace cmdlet. This is a mandatory parameter if WorkspaceId is not provided. |
| 15 | +
|
| 16 | +.EXAMPLE |
| 17 | +Get-FabricWorkspaceUser -WorkspaceId '12345678-1234-1234-1234-123456789012 |
| 18 | +
|
| 19 | +This example retrieves the users of a workspace of the workspace with the ID '12345678-1234-1234-1234-123456789012'. |
| 20 | +
|
| 21 | +.EXAMPLE |
| 22 | +$workspace = Get-FabricWorkspace -WorkspaceName 'prod-workspace' |
| 23 | +$workspace | Get-FabricWorkspaceUser |
| 24 | +
|
| 25 | +This example retrieves the users of the prod-workspace workspace by piping the object. |
| 26 | +
|
| 27 | +.EXAMPLE |
| 28 | +Get-FabricWorkspaceUser -Workspace (Get-FabricWorkspace -WorkspaceName 'prod-workspace') |
| 29 | +
|
| 30 | +This example retrieves the users of the prod-workspace workspace by piping the object. |
| 31 | +
|
| 32 | +.EXAMPLE |
| 33 | +Get-FabricWorkspace| Get-FabricWorkspaceUser |
| 34 | +
|
| 35 | +This example retrieves the users of all of the workspaces. IMPORTANT: This will not return the workspace name or ID at present. |
| 36 | +
|
| 37 | +.EXAMPLE |
| 38 | +Get-FabricWorkspace| Foreach-Object { |
| 39 | +Get-FabricWorkspaceUser -WorkspaceId $_.Id | Select-Object @{Name='WorkspaceName';Expression={$_.displayName;}}, * |
| 40 | +} |
| 41 | +
|
| 42 | +This example retrieves the users of all of the workspaces. It will also add the workspace name to the output. |
| 43 | +
|
| 44 | +.NOTES |
| 45 | +It supports multiple aliases for backward compatibility. |
| 46 | +The function defines parameters for the workspace ID and workspace object. If the parameter set name is 'WorkspaceId', it retrieves the workspace object. It then makes a GET request to the PowerBI API to retrieve the users of the workspace and returns the 'value' property of the response, which contains the users. |
| 47 | +
|
| 48 | +Author: Ioana Bouariu |
| 49 | +
|
| 50 | + #> |
| 51 | + |
| 52 | + # This function retrieves the users of a workspace. |
| 53 | + # Define aliases for the function for flexibility. |
| 54 | + [Alias("Get-FabWorkspaceUsers")] |
| 55 | + [Alias("Get-FabricWorkspaceUsers")] |
| 56 | + |
| 57 | + # Define parameters for the workspace ID and workspace object. |
| 58 | + param( |
| 59 | + [Parameter(Mandatory = $true, ParameterSetName = 'WorkspaceId')] |
| 60 | + [string]$WorkspaceId, |
| 61 | + |
| 62 | + [Parameter(Mandatory = $true, ParameterSetName = 'WorkspaceObject', ValueFromPipeline = $true )] |
| 63 | + [object[]] |
| 64 | + $Workspace |
| 65 | + ) |
| 66 | + |
| 67 | + begin |
| 68 | + { |
| 69 | + Confirm-TokenState |
| 70 | + # If the parameter set name is 'WorkspaceId', return the workspace object so that it can be used in the process block. |
| 71 | + if ($PSCmdlet.ParameterSetName -eq 'WorkspaceId') |
| 72 | + { |
| 73 | + $Workspace = Get-FabricWorkspace -WorkspaceId $WorkspaceId |
| 74 | + } |
| 75 | + $returnValue = @() |
| 76 | + } |
| 77 | + |
| 78 | + process |
| 79 | + { |
| 80 | + |
| 81 | + foreach ($space in $Workspace) |
| 82 | + { |
| 83 | + |
| 84 | + $Uri = "groups/{0}/users" -f $space.id |
| 85 | + |
| 86 | + # Make a GET request to the PowerBI API to retrieve the users of the workspace. |
| 87 | + # The function returns the 'value' property of the response, which contains the users. |
| 88 | + |
| 89 | + $response = (Invoke-FabricRestMethod -Method get -PowerBIApi -Uri $Uri).value |
| 90 | + if ($response) |
| 91 | + { |
| 92 | + |
| 93 | + # Add the users to the return value. |
| 94 | + $returnValue += $response |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + end |
| 99 | + { |
| 100 | + $returnValue |
| 101 | + } |
| 102 | +} |
0 commit comments