Repository navigation
Expand file tree
/
Copy pathAdd-FabricDomainWorkspaceById.ps1
More file actions
74 lines (58 loc) · 2.58 KB
/
Copy pathAdd-FabricDomainWorkspaceById.ps1
File metadata and controls
74 lines (58 loc) · 2.58 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
<#
.SYNOPSIS
Assigns workspaces to a specified domain in Microsoft Fabric by their IDs.
.DESCRIPTION
The `Add-FabricDomainWorkspaceById` function sends a request to assign multiple workspaces to a specified domain using the provided domain ID and an array of workspace IDs.
.PARAMETER DomainId
The ID of the domain to which workspaces will be assigned. This parameter is mandatory.
.PARAMETER WorkspaceIds
An array of workspace IDs to be assigned to the domain. This parameter is mandatory.
.EXAMPLE
Add-FabricDomainWorkspaceById -DomainId "12345" -WorkspaceIds @("ws1", "ws2", "ws3")
Assigns the workspaces with IDs "ws1", "ws2", and "ws3" to the domain with ID "12345".
.NOTES
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
Author: Tiago Balabuch
#>
function Add-FabricDomainWorkspaceById {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$DomainId,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[array]$WorkspaceIds
)
try {
# Validate authentication token before proceeding
Invoke-FabricAuthCheck -ThrowOnFailure
# Construct the API endpoint URI
$apiEndpointURI = New-FabricAPIUri -Segments @('admin', 'domains', $DomainId, 'assignWorkspaces')
Write-FabricLog -Message "API Endpoint: $apiEndpointURI" -Level Debug
# Construct the request body
$body = @{
workspacesIds = $WorkspaceIds
}
$bodyJson = Convert-FabricRequestBody -InputObject $body
Write-FabricLog -Message "Request Body: $bodyJson" -Level Debug
# Make the API request (guarded by ShouldProcess)
if ($PSCmdlet.ShouldProcess($DomainId, 'Assign workspaces to domain by IDs')) {
$apiParams = @{
BaseURI = $apiEndpointURI
Headers = $script:FabricAuthContext.FabricHeaders
Method = 'Post'
Body = $bodyJson
}
$response = Invoke-FabricAPIRequest @apiParams
Write-FabricLog -Message "Successfully assigned workspaces to the domain with ID '$DomainId'." -Level Host
$response
}
}
catch {
# Capture and log error details
$errorDetails = $_.Exception.Message
Write-FabricLog -Message "Failed to assign workspaces to the domain with ID '$DomainId'. Error: $errorDetails" -Level Error
}
}