Repository navigation
Expand file tree
/
Copy pathGet-FabricWorkspace.ps1
More file actions
85 lines (65 loc) · 2.65 KB
/
Copy pathGet-FabricWorkspace.ps1
File metadata and controls
85 lines (65 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<#
.SYNOPSIS
Retrieves details of a Microsoft Fabric workspace by its ID or name.
.DESCRIPTION
The `Get-FabricWorkspace` function fetches workspace details from the Fabric API. It supports filtering by WorkspaceId or WorkspaceName.
.PARAMETER WorkspaceId
The unique identifier of the workspace to retrieve.
.PARAMETER WorkspaceName
The display name of the workspace to retrieve.
.PARAMETER Raw
When specified, returns the raw API response with resolved CapacityName property
added directly to the output objects. Useful for piping to Export-Csv, ConvertTo-Json, or other commands.
.EXAMPLE
Get-FabricWorkspace -WorkspaceId "workspace123"
Fetches details of the workspace with ID "workspace123".
.EXAMPLE
Get-FabricWorkspace -WorkspaceName "MyWorkspace"
Fetches details of the workspace with the name "MyWorkspace".
.EXAMPLE
Get-FabricWorkspace -Raw | Export-Csv -Path "workspaces.csv"
Exports all workspaces with resolved CapacityName to a CSV file.
.NOTES
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
- Returns the matching workspace details or all workspaces if no filter is provided.
Author: Tiago Balabuch
#>
function Get-FabricWorkspace {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$WorkspaceId,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$WorkspaceName,
[Parameter()]
[switch]$Raw
)
try {
# Validate input parameters
if ($WorkspaceId -and $WorkspaceName) {
Write-FabricLog -Message "Specify only one parameter: either 'WorkspaceId' or 'WorkspaceName'." -Level Error
return
}
# Validate authentication
Invoke-FabricAuthCheck -ThrowOnFailure
# Construct the API endpoint URI
$apiEndpointURI = New-FabricAPIUri -Resource 'workspaces'
# Make the API request
$apiParams = @{
BaseURI = $apiEndpointURI
Headers = $script:FabricAuthContext.FabricHeaders
Method = 'Get'
}
$dataItems = Invoke-FabricAPIRequest @apiParams
# Apply filtering and output results with type decoration
Select-FabricResource -InputObject $dataItems -Id $WorkspaceId -DisplayName $WorkspaceName -ResourceType 'Workspace' -TypeName 'MicrosoftFabric.Workspace' -Raw:$Raw
}
catch {
# Capture and log error details
$errorDetails = $_.Exception.Message
Write-FabricLog -Message "Failed to retrieve workspace. Error: $errorDetails" -Level Error
}
}