Skip to content

Commit 823d3ef

Browse files
committed
Initial version of Update-FabricCapacity cmdlet #161
1 parent 91b0579 commit 823d3ef

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
function Update-FabricCapacity
2+
{
3+
<#
4+
.SYNOPSIS
5+
Creates or updates a Microsoft Fabric capacity.
6+
7+
.DESCRIPTION
8+
The `Update-FabricCapacity` function sends a PATCH request to the Microsoft Fabric API to create or update a capacity
9+
in the specified Azure subscription and resource group. It supports parameters for capacity administration,
10+
SKU details, and optional tags.
11+
12+
.PARAMETER SubscriptionId
13+
The ID of the target subscription. The value must be a UUID.
14+
15+
.PARAMETER ResourceGroupName
16+
The name of the resource group. The name is case insensitive.
17+
18+
.PARAMETER CapacityName
19+
The name of the Microsoft Fabric capacity. It must be a minimum of 3 characters, and a maximum of 63.
20+
Must match pattern: ^[a-z][a-z0-9]*$
21+
22+
.PARAMETER SkuName
23+
The name of the SKU level (e.g., "F2").
24+
25+
.PARAMETER AdministrationMembers
26+
An array of administrator user identities for the capacity administration.
27+
28+
.PARAMETER Tags
29+
Optional resource tags as a hashtable.
30+
31+
.PARAMETER NoWait
32+
If specified, the function will not wait for the operation to complete and will return immediately.
33+
34+
.EXAMPLE
35+
```powershell
36+
Update-FabricCapacity -SubscriptionId "548B7FB7-3B2A-4F46-BB02-66473F1FC22C" -ResourceGroupName "TestRG" -CapacityName "azsdktest" -SkuName "F2" -AdministrationMembers @("azsdktest@microsoft.com", "azsdktest2@microsoft.com")
37+
```
38+
39+
.EXAMPLE
40+
```powershell
41+
Update-FabricCapacity -SubscriptionId "548B7FB7-3B2A-4F46-BB02-66473F1FC22C" -ResourceGroupName "TestRG" -CapacityName "azsdktest" -SkuName "F2" -AdministrationMembers @("admin@company.com") -Tags @{Environment="Production"; Owner="IT Team"}
42+
```
43+
44+
.NOTES
45+
- Calls `Confirm-TokenState` to ensure token validity before making the API request.
46+
- Uses Azure Resource Manager API endpoint for capacity management.
47+
48+
Author: Kamil Nowinski
49+
50+
#>
51+
[CmdletBinding(SupportsShouldProcess)]
52+
param (
53+
[Parameter(Mandatory = $true)]
54+
[ValidateNotNullOrEmpty()]
55+
[guid]$SubscriptionId,
56+
57+
[Parameter(Mandatory = $true)]
58+
[ValidateNotNullOrEmpty()]
59+
[ValidateLength(1, 90)]
60+
[string]$ResourceGroupName,
61+
62+
[Parameter(Mandatory = $true)]
63+
[ValidateNotNullOrEmpty()]
64+
[ValidateLength(3, 63)]
65+
[ValidatePattern('^[a-z][a-z0-9]*$')]
66+
[string]$CapacityName,
67+
68+
[Parameter(Mandatory = $true)]
69+
[ValidateNotNullOrEmpty()]
70+
[string]$SkuName,
71+
72+
[Parameter(Mandatory = $true)]
73+
[ValidateNotNullOrEmpty()]
74+
[string[]]$AdministrationMembers,
75+
76+
[Parameter(Mandatory = $false)]
77+
[hashtable]$Tags,
78+
79+
[switch]$NoWait = $false
80+
)
81+
82+
$SkuTier = "Fabric"
83+
84+
try
85+
{
86+
# Step 1: Ensure token validity
87+
Confirm-TokenState
88+
89+
# Step 2: Construct the API URL
90+
$apiEndpointUrl = "$($AzureSession.BaseApiUrl)/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Fabric/capacities/{2}?api-version=2023-11-01" -f $SubscriptionId, $ResourceGroupName, $CapacityName
91+
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
92+
93+
# Step 3: Construct the request body
94+
$body = @{
95+
properties = @{
96+
administration = @{
97+
members = $AdministrationMembers
98+
}
99+
}
100+
sku = @{
101+
name = $SkuName
102+
tier = $SkuTier
103+
}
104+
}
105+
106+
if ($Tags)
107+
{
108+
$body.tags = $Tags
109+
}
110+
111+
# Step 4: Make the API request
112+
if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update Fabric Capacity"))
113+
{
114+
$apiParams = @{
115+
Uri = $apiEndpointUrl
116+
Method = 'PATCH'
117+
Body = $body
118+
TypeName = 'Fabric Capacity'
119+
NoWait = $NoWait
120+
HandleResponse = $true
121+
ObjectIdOrName = $CapacityName
122+
}
123+
$response = Invoke-FabricRestMethod @apiParams
124+
$response
125+
}
126+
}
127+
catch
128+
{
129+
# Step 5: Handle and log errors
130+
$errorDetails = $_.Exception.Message
131+
Write-Message -Message "Failed to update Fabric Capacity. Error: $errorDetails" -Level Error
132+
throw
133+
}
134+
}

0 commit comments

Comments
 (0)