@@ -13,8 +13,12 @@ function Get-FabricSQLDatabase {
13
13
Id of the Fabric Workspace for which the SQLDatabases should be retrieved. The value for WorkspaceId is a GUID.
14
14
An example of a GUID is '12345678-1234-1234-1234-123456789012'.
15
15
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
+
16
20
. 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.
18
22
19
23
. PARAMETER SQLDatabaseID
20
24
The Id of the SQLDatabase to retrieve. This parameter cannot be used together with SQLDatabaseName.
@@ -28,7 +32,7 @@ function Get-FabricSQLDatabase {
28
32
This example will retrieve the SQLDatabase with the name 'MySQLDatabase'.
29
33
30
34
. EXAMPLE
31
- Get-FabricSQLDatabase
35
+ Get-FabricSQLDatabase -WorkspaceId '12345678-1234-1234-1234-123456789012'
32
36
33
37
This example will retrieve all SQLDatabases in the workspace that is specified
34
38
by the WorkspaceId.
@@ -40,6 +44,11 @@ function Get-FabricSQLDatabase {
40
44
41
45
This example will retrieve the SQLDatabase with the ID '12345678-1234-1234-1234-123456789012'.
42
46
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
+
43
52
. NOTES
44
53
Revision History:
45
54
- 2025-03-06 - KNO: Init version of the function
@@ -51,31 +60,54 @@ function Get-FabricSQLDatabase {
51
60
52
61
[CmdletBinding ()]
53
62
param (
54
- [Parameter (Mandatory = $true )]
63
+ [Parameter (Mandatory = $true , ParameterSetName = ' WorkspaceId ' )]
55
64
[string ]$WorkspaceId ,
56
65
66
+ [Parameter (Mandatory = $true , ParameterSetName = ' WorkspaceObject' , ValueFromPipeline = $true )]
67
+ $Workspace ,
68
+
57
69
[Alias (" Name" , " DisplayName" )]
58
70
[string ]$SQLDatabaseName ,
59
71
60
72
[Alias (" Id" )]
61
73
[string ]$SQLDatabaseId
62
74
)
63
75
64
- Confirm-TokenState
76
+ begin {
77
+ Confirm-TokenState
65
78
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
+ }
69
82
}
70
83
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
75
112
}
76
- $result = Invoke-RestMethod - Headers $FabricSession.HeaderParams - Uri $uri
77
- # #$databases.Where({$_.displayName -eq $body.displayName}).id
78
-
79
- return $result.value
80
-
81
113
}
0 commit comments