Repository navigation
Expand file tree
/
Copy pathGet-FabricOneLakeShortcut.ps1
More file actions
147 lines (121 loc) · 5.35 KB
/
Copy pathGet-FabricOneLakeShortcut.ps1
File metadata and controls
147 lines (121 loc) · 5.35 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<#
.SYNOPSIS
Retrieves shortcut details from a specified Microsoft Fabric OneLake item.
.DESCRIPTION
Fetches shortcut information from a OneLake item within a workspace. Supports filtering by shortcut name and parent path.
Validates authentication, constructs the API endpoint, sends the request, and returns the matching shortcut(s).
.PARAMETER WorkspaceId
The unique identifier of the workspace containing the OneLake item. Mandatory.
.PARAMETER ItemId
The unique identifier of the OneLake item to query. Mandatory.
.PARAMETER ShortcutName
The name of the shortcut to retrieve. Optional.
.PARAMETER ParentPath
The parent path to filter shortcuts. Optional.
.PARAMETER Raw
If specified, returns the untouched API response with no added properties or type decoration.
.EXAMPLE
Get-FabricOneLakeShortcut -WorkspaceId "workspace-12345" -ItemId "item-67890"
Retrieves all shortcuts for the specified OneLake item.
.EXAMPLE
Get-FabricOneLakeShortcut -WorkspaceId "workspace-12345" -ItemId "item-67890" -ShortcutName "MyShortcut"
Retrieves the shortcut named "MyShortcut" for the specified OneLake item.
.NOTES
- Requires `$FabricConfig` global configuration with `BaseUrl` and `FabricHeaders`.
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
Author: Tiago Balabuch
#>
function Get-FabricOneLakeShortcut {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Alias('id')]
[string]$WorkspaceId,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$ItemId,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$ShortcutName,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$ParentPath,
[Parameter()]
[switch]$Raw
)
process {
try {
Invoke-FabricAuthCheck -ThrowOnFailure
# Construct the API endpoint URI
$apiEndpointURI = "{0}/workspaces/{1}/items/{2}/shortcuts" -f $script:FabricAuthContext.BaseUrl, $WorkspaceId, $ItemId
if ($ParentPath) {
$apiEndpointURI += "?parentPath={0}" -f $ParentPath
}
Write-FabricLog -Message "API Endpoint: $apiEndpointURI" -Level Debug
# Make the API request
$apiParams = @{
BaseURI = $apiEndpointURI
Headers = $script:FabricAuthContext.FabricHeaders
Method = 'Get'
}
$dataItems = Invoke-FabricAPIRequest @apiParams
# Immediately handle empty response
if (-not $dataItems) {
Write-FabricLog -Message "No data returned from the API." -Level Warning
return $null
}
# Apply filtering logic efficiently
if ($ShortcutName) {
$matchedItems = $dataItems.Where({ $_.name -eq $ShortcutName }, 'First')
}
else {
Write-FabricLog -Message "No filter provided. Returning all items." -Level Debug
$matchedItems = $dataItems
}
# Handle results
if (-not $matchedItems) {
Write-FabricLog -Message "No item found matching the provided criteria." -Level Warning
return $null
}
if ($Raw) {
return $matchedItems
}
Write-FabricLog -Message "Item(s) found matching the specified criteria." -Level Debug
# Enrich with resolved workspace and capacity names
$workspaceName = $null
try {
$workspaceName = Resolve-FabricWorkspaceName -WorkspaceId $WorkspaceId
}
catch {
$workspaceName = $WorkspaceId
Write-FabricLog -Message "Failed to resolve workspace name for ID '$WorkspaceId': $($_.Exception.Message)" -Level Debug
}
$capacityName = $null
try {
$capacityId = Resolve-FabricCapacityIdFromWorkspace -WorkspaceId $WorkspaceId
if ($capacityId) {
$capacityName = Resolve-FabricCapacityName -CapacityId $capacityId
}
}
catch {
Write-FabricLog -Message "Failed to resolve capacity name for workspace ID '$WorkspaceId': $($_.Exception.Message)" -Level Debug
}
foreach ($item in $matchedItems) {
$item | Add-Member -NotePropertyName 'workspaceId' -NotePropertyValue $WorkspaceId -Force
$item | Add-Member -NotePropertyName 'WorkspaceName' -NotePropertyValue $workspaceName -Force
if ($null -ne $capacityName) {
$item | Add-Member -NotePropertyName 'CapacityName' -NotePropertyValue $capacityName -Force
}
}
# Add type decoration for custom formatting
$matchedItems | Add-FabricTypeName -TypeName 'MicrosoftFabric.OneLakeShortcut'
return $matchedItems
}
catch {
# Capture and log error details
$errorDetails = $_.Exception.Message
Write-FabricLog -Message "Failed to retrieve OneLake Shortcut(s). Error details: $errorDetails" -Level Error
}
}
}