Repository navigation
Expand file tree
/
Copy pathGet-FabricKQLDatabaseDefinition.ps1
More file actions
95 lines (77 loc) · 3.4 KB
/
Copy pathGet-FabricKQLDatabaseDefinition.ps1
File metadata and controls
95 lines (77 loc) · 3.4 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
<#
.SYNOPSIS
Retrieves the definition of a KQLDatabase from a specific workspace in Microsoft Fabric.
.DESCRIPTION
This function fetches the KQLDatabase's content or metadata from a workspace.
It supports retrieving KQLDatabase definitions in the Jupyter KQLDatabase (`ipynb`) format.
Handles both synchronous and asynchronous operations, with detailed logging and error handling.
.PARAMETER WorkspaceId
(Mandatory) The unique identifier of the workspace from which the KQLDatabase definition is to be retrieved.
.PARAMETER KQLDatabaseId
(Optional)The unique identifier of the KQLDatabase whose definition needs to be retrieved.
.PARAMETER KQLDatabaseFormat
Specifies the format of the KQLDatabase definition. Currently, only 'ipynb' is supported.
.PARAMETER Raw
If specified, returns the untouched API response.
.EXAMPLE
Get-FabricKQLDatabaseDefinition -WorkspaceId "12345" -KQLDatabaseId "67890"
Retrieves the definition of the KQLDatabase with ID `67890` from the workspace with ID `12345` in the `ipynb` format.
.EXAMPLE
Get-FabricKQLDatabaseDefinition -WorkspaceId "12345"
Retrieves the definitions of all KQLDatabases in the workspace with ID `12345` in the `ipynb` format.
.NOTES
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
- Handles long-running operations asynchronously.
Author: Updated by Jess Pomfret and Rob Sewell November 2026
#>
function Get-FabricKQLDatabaseDefinition {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Alias('id')]
[string]$WorkspaceId,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$KQLDatabaseId,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$KQLDatabaseFormat,
[Parameter()]
[switch]$Raw
)
process {
try {
# Validate authentication token before proceeding.
Write-FabricLog -Message "Validating authentication token..." -Level Debug
Test-TokenExpired
Write-FabricLog -Message "Authentication token is valid." -Level Debug
# Construct the API endpoint URI with filtering logic
$apiEndpointURI = "{0}/workspaces/{1}/KQLDatabases/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDatabaseId
if ($KQLDatabaseFormat) {
$apiEndpointURI = "{0}?format={1}" -f $apiEndpointURI, $KQLDatabaseFormat
}
Write-FabricLog -Message "API Endpoint: $apiEndpointURI" -Level Debug
# Make the API request
$apiParams = @{
BaseURI = $apiEndpointURI
Headers = $FabricConfig.FabricHeaders
Method = 'Post'
}
$response = Invoke-FabricAPIRequest @apiParams
if ($Raw) {
return $response
}
# Return the API response
Write-FabricLog -Message "KQLDatabase '$KQLDatabaseId' definition retrieved successfully!" -Level Debug
return $response
}
catch {
# Capture and log error details
$errorDetails = $_.Exception.Message
Write-FabricLog -Message "Failed to retrieve KQLDatabase. Error: $errorDetails" -Level Error
}
}
}