Home > Software engineering >  PowerShell script to check if autoscale is enabled in Azure Cosmos
PowerShell script to check if autoscale is enabled in Azure Cosmos

Time:06-10

I am writing a powershell script that checks if autoscale is enabled in cosmosdb and if it isn't then it should enable autoscaling. I am not able to find a powershell script or command that lets us check if autoscaling is enabled or not. I am referring the following document which only has a command to enable autoscaling.

https://docs.microsoft.com/en-us/azure/cosmos-db/scripts/powershell/sql/throughput?toc=/powershell/module/toc.json

CodePudding user response:

You could check if the autoscaling is enabled or not on a container by inspecting AutoscaleSettings of the $througput object returned by the Cmdlet. If a container has the throughput set as Manual, then MaxThrougput property of the auto scale settings would return zero.

$account = "account-name"
$resourceGroup = "resource-group-name"
$database = "database-name"
$container = "container-name"

$throughput = Get-AzCosmosDBSqlContainerThroughput -ResourceGroupName $resourceGroup `
    -AccountName $account -DatabaseName $database -Name $container

$autoscaleSettings = $throughput.AutoscaleSettings

if ($autoscaleSettings.MaxThroughput -eq 0) {
  Write-Host "Autoscaling is not set on the container"
} else {
  Write-Host "Autoscaling is set on the container"
}
  • Related