This repository contains a PowerShell script to automate the resume and suspend operations of Microsoft Fabric capacity using Azure Automation Account. The automation helps in optimizing costs by stopping the capacity when not in use and resuming it when needed.
✅ Automates Fabric capacity start (resume
) and stop (suspend
).
✅ Uses Azure Automation Account to run the script on a schedule.
✅ Helps in cost optimization by pausing unused capacity.
✅ Secure authentication using Managed Identity.
Before setting up the automation, ensure you have:
- An Azure subscription with necessary permissions.
- A Microsoft Fabric capacity resource.
- An Azure Automation Account with system-managed identity enabled.
- The latest Az PowerShell module installed in the automation environment.
- Go to the Azure Portal → Create an Automation Account.
- Enable System Managed Identity under the Identity section.
- Navigate to Runbooks in Azure Automation.
- Create a new PowerShell Runbook and paste the following script:
Param(
[string]$ResourceID,
[string]$operation # "resume" or "suspend"
)
Connect-AzAccount -Identity
$tokenObject = Get-AzAccessToken -ResourceUrl "https://management.azure.com/"
$token = $tokenObject.Token
$url = "https://management.azure.com$ResourceID/$operation?api-version=2022-07-01-preview"
$headers = @{
'Content-Type' = 'application/json'
'Authorization' = "Bearer $token"
}
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers
Write-Output "Operation $operation executed successfully for $ResourceID"
- Grant the Automation Account the required role on the Fabric capacity resource:
Role: Contributor Scope: Microsoft.Fabric Capacity Resource
- In Azure Automation, navigate to the Schedules section.
- Create a new schedule to run the script based on working hours(Suspend - 5 PM To 8 AM and start(Monday - Friday), Start 8 AM - 5 PM Weekdays (Mon-Fri)).
- Link the schedule to the runbook.
Run the script manually or schedule it with parameters:
# Example: Resume Fabric Capacity
.\Runbook.ps1 -ResourceID "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Fabric/capacities/myFabric" -operation "resume"
# Example: Suspend Fabric Capacity
.\Runbook.ps1 -ResourceID "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Fabric/capacities/myFabric" -operation "suspend"
- Runbook fails to authenticate? Ensure that Managed Identity is enabled and has the right permissions.
- Permission denied errors? Verify that the Automation Account has the
Contributor
role on the Fabric resource. - API version issues? Ensure the correct API version (
2022-07-01-preview
) is used.
Feel free to submit issues or pull requests if you have improvements!