Repository navigation
Expand file tree
/
Copy pathAdd-FabricDomainWorkspaceByCapacity.ps1
More file actions
74 lines (59 loc) · 2.65 KB
/
Copy pathAdd-FabricDomainWorkspaceByCapacity.ps1
File metadata and controls
74 lines (59 loc) · 2.65 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 Fabric domain based on specified capacities.
.DESCRIPTION
The `Add-FabricDomainWorkspaceByCapacity` function assigns workspaces to a Fabric domain using a list of capacity IDs by making a POST request to the relevant API endpoint.
.PARAMETER DomainId
The unique identifier of the Fabric domain to which the workspaces will be assigned.
.PARAMETER CapacitiesIds
An array of capacity IDs used to assign workspaces to the domain.
.EXAMPLE
Add-FabricDomainWorkspaceByCapacity -DomainId "12345" -CapacitiesIds @("capacity1", "capacity2")
Assigns workspaces to the domain with ID "12345" based on the specified capacities.
.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-FabricDomainWorkspaceByCapacity {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
[Alias('Assign-FabricDomainWorkspaceByCapacity')]
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$DomainId,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[array]$CapacitiesIds
)
try {
# Validate authentication token before proceeding
Invoke-FabricAuthCheck -ThrowOnFailure
# Construct the API endpoint URI
$apiEndpointURI = New-FabricAPIUri -Segments @('admin', 'domains', $DomainId, 'assignWorkspacesByCapacities')
Write-FabricLog -Message "API Endpoint: $apiEndpointURI" -Level Debug
# Construct the request body
$body = @{
capacitiesIds = $CapacitiesIds
}
$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 capacities')) {
$apiParams = @{
BaseURI = $apiEndpointURI
Headers = $script:FabricAuthContext.FabricHeaders
Method = 'Post'
Body = $bodyJson
}
$response = Invoke-FabricAPIRequest @apiParams
Write-FabricLog -Message "Assigning domain workspaces by capacity completed successfully!" -Level Host
$response
}
}
catch {
# Capture and log error details
$errorDetails = $_.Exception.Message
Write-FabricLog -Message "Error occurred while assigning workspaces by capacity for domain '$DomainId'. Details: $errorDetails" -Level Error
}
}