Skip to content

PowerShell script to automate Microsoft Fabric capacity start (resume) and stop (suspend) using Azure Automation Account. Helps optimize costs by pausing unused capacity based on a schedule.

Notifications You must be signed in to change notification settings

jagdish0909/microsoft-fabric-resume-pause

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Microsoft Fabric Capacity Automation 🚀

Overview

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.

Features

✅ 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.

Prerequisites

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.

Setup Guide

1️⃣ Create an Azure Automation Account

  1. Go to the Azure Portal → Create an Automation Account.
  2. Enable System Managed Identity under the Identity section.

2️⃣ Import the PowerShell Runbook

  1. Navigate to Runbooks in Azure Automation.
  2. 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"

3️⃣ Assign Permissions

  • Grant the Automation Account the required role on the Fabric capacity resource:
    Role: Contributor  
    Scope: Microsoft.Fabric Capacity Resource  

4️⃣ Schedule the Runbook

  1. In Azure Automation, navigate to the Schedules section.
  2. 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)).
  3. Link the schedule to the runbook.

Usage

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"

Troubleshooting

  • 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.

Contributing

Feel free to submit issues or pull requests if you have improvements!

About

PowerShell script to automate Microsoft Fabric capacity start (resume) and stop (suspend) using Azure Automation Account. Helps optimize costs by pausing unused capacity based on a schedule.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published