@@ -13,8 +13,12 @@ function Get-FabricSQLDatabase {
1313 Id of the Fabric Workspace for which the SQLDatabases should be retrieved. The value for WorkspaceId is a GUID.
1414 An example of a GUID is '12345678-1234-1234-1234-123456789012'.
1515
16+ . PARAMETER Workspace
17+ The workspace object. This is a mandatory parameter for the 'WorkspaceObject' parameter set and can be pipelined into the function.
18+ The object can be easily retrieved by Get-FabricWorkspace function.
19+
1620. PARAMETER SQLDatabaseName
17- The name of the KQLDatabase to retrieve. This parameter cannot be used together with SQLDatabaseID.
21+ The name of the SQLDatabase to retrieve. This parameter cannot be used together with SQLDatabaseID.
1822
1923. PARAMETER SQLDatabaseID
2024 The Id of the SQLDatabase to retrieve. This parameter cannot be used together with SQLDatabaseName.
@@ -28,7 +32,7 @@ function Get-FabricSQLDatabase {
2832 This example will retrieve the SQLDatabase with the name 'MySQLDatabase'.
2933
3034. EXAMPLE
31- Get-FabricSQLDatabase
35+ Get-FabricSQLDatabase -WorkspaceId '12345678-1234-1234-1234-123456789012'
3236
3337 This example will retrieve all SQLDatabases in the workspace that is specified
3438 by the WorkspaceId.
@@ -40,6 +44,11 @@ function Get-FabricSQLDatabase {
4044
4145 This example will retrieve the SQLDatabase with the ID '12345678-1234-1234-1234-123456789012'.
4246
47+ . EXAMPLE
48+ Get-FabricWorkspace -WorkspaceName 'MsLearn-dev' | Get-FabricSQLDatabase
49+
50+ This example will retrieve all SQLDatabases from the workspace with the name 'MsLearn-dev' (using the pipeline).
51+
4352. NOTES
4453 Revision History:
4554 - 2025-03-06 - KNO: Init version of the function
@@ -51,31 +60,54 @@ function Get-FabricSQLDatabase {
5160
5261 [CmdletBinding ()]
5362 param (
54- [Parameter (Mandatory = $true )]
63+ [Parameter (Mandatory = $true , ParameterSetName = ' WorkspaceId ' )]
5564 [string ]$WorkspaceId ,
5665
66+ [Parameter (Mandatory = $true , ParameterSetName = ' WorkspaceObject' , ValueFromPipeline = $true )]
67+ $Workspace ,
68+
5769 [Alias (" Name" , " DisplayName" )]
5870 [string ]$SQLDatabaseName ,
5971
6072 [Alias (" Id" )]
6173 [string ]$SQLDatabaseId
6274 )
6375
64- Confirm-TokenState
76+ begin {
77+ Confirm-TokenState
6578
66- Write-Verbose " You can either use SQLDatabaseName or SQLDatabaseID not both. If both are used throw error "
67- if ( $PSBoundParameters .ContainsKey ( " SQLDatabaseName" ) - and $PSBoundParameters .ContainsKey ( " SQLDatabaseId" )) {
68- throw " Parameters SQLDatabaseName and SQLDatabaseId cannot be used together "
79+ if ( $PSBoundParameters .ContainsKey ( " SQLDatabaseName" ) -and $PSBoundParameters .ContainsKey ( " SQLDatabaseId " )) {
80+ throw " Parameters SQLDatabaseName and SQLDatabaseId cannot be used together "
81+ }
6982 }
7083
71- # Create SQLDatabase API
72- $uri = " $ ( $FabricSession.BaseApiUrl ) /workspaces/$workspaceId /SqlDatabases"
73- if ($SQLDatabaseId ) {
74- $uri = " $uri /$SQLDatabaseId "
84+ process {
85+ if ($PSCmdlet.ParameterSetName -eq ' WorkspaceObject' ) {
86+ $WorkspaceId = $Workspace.id
87+ }
88+
89+ # Create SQLDatabase API
90+ $uri = " $ ( $FabricSession.BaseApiUrl ) /workspaces/$WorkspaceId /SqlDatabases"
91+ if ($SQLDatabaseId ) {
92+ $uri = " $uri /$SQLDatabaseId "
93+ }
94+ $response = Invoke-FabricRestMethod - Uri $uri
95+ # #$databases.Where({$_.displayName -eq $body.displayName}).id
96+
97+ # Step: Validate the response code
98+ if ($statusCode -ne 200 ) {
99+ Write-Message - Message " Unexpected response code: $statusCode from the API." - Level Error
100+ Write-Message - Message " Error: $ ( $response.message ) " - Level Error
101+ Write-Message - Message " Error Details: $ ( $response.moreDetails ) " - Level Error
102+ Write-Message " Error Code: $ ( $response.errorCode ) " - Level Error
103+ return $null
104+ }
105+
106+ $response = $response.value
107+ if ($SQLDatabaseName ) {
108+ # Filter the SQLDatabase by name
109+ $response = $response | Where-Object { $_.displayName -eq $SQLDatabaseName }
110+ }
111+ return $response
75112 }
76- $result = Invoke-RestMethod - Headers $FabricSession.HeaderParams - Uri $uri
77- # #$databases.Where({$_.displayName -eq $body.displayName}).id
78-
79- return $result.value
80-
81113}
0 commit comments