Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Resize script for an Azure CosmosDB account of any type.
param(
[Parameter(Mandatory = $true)]
[string] $ResourceGroupName,
[Parameter(Mandatory = $true)]
[string] $AccountName,
[Parameter(Mandatory = $true)]
[string] $DatabaseName,
[Parameter(Mandatory = $true)]
[string] $ContainerName,
[Parameter(Mandatory = $true, HelpMessage="Values between 400 and 1000000 inclusive in increments of 100")]
[int] $Throughput
)
if ( $Throughput -lt 400 -or $Throughput -gt 1000000 -or ($Throughput % 100) -ne 0 ){
$message = "Invalid Throughput $Throughput. Values between 400 and 1000000 inclusive in increments of 100"
Write-Error -Message $message
return
}
$ErrorActionPreference = "Continue"
$p = Get-AzResource `
-ResourceType "Microsoft.DocumentDb/databaseAccounts" -ApiVersion "2016-03-31" `
-ResourceGroupName $ResourceGroupName -Name $accountName `
| Select-Object -expand Properties
$accountType = $p.EnabledApiTypes
$resourceType = ''
$resourceName = ''
if ($accountType -match 'Table'){
$resourceType = 'Microsoft.DocumentDb/databaseAccounts/apis/tables/settings'
$resourceName = $accountName + "/table/" + $ContainerName + "/throughput"
}
elseif ($accountType -match 'MongoDB'){
$resourceType = 'Microsoft.DocumentDb/databaseAccounts/apis/databases/collections/settings';
$resourceName = $accountName + "/mongodb/" + $DatabaseName + "/" + $ContainerName + "/throughput"
}
elseif ($accountType -match 'Gremlin'){
$resourceType = 'Microsoft.DocumentDb/databaseAccounts/apis/databases/graphs/settings';
$resourceName = $accountName + "/gremlin/" + $DatabaseName + "/" + $ContainerName + "/throughput"
}
elseif ($accountType -match 'Cassandra'){
$resourceType = 'Microsoft.DocumentDB/databaseAccounts/apis/keyspaces/tables/settings';
$resourceName = $accountName + "/cassandra/" + $DatabaseName + "/" + $ContainerName + "/throughput"
}
elseif ($accountType -match 'Sql'){
$resourceType = 'Microsoft.DocumentDb/databaseAccounts/apis/databases/containers/settings';
$resourceName = $accountName + "/sql/" + $DatabaseName + "/" + $ContainerName + "/throughput"
}
else{
$message = "Unsupported CosmosDB account type '$accountType'. Supported APIs are: SQL, Gremlin, MongoDB, Table and Cassandra."
Write-Error -Message $message
return
}
$properties = @{
"resource"=@{"throughput"=$throughput}
}
try {
Set-AzResource `
-ResourceType $resourceType -ApiVersion "2016-03-31" `
-ResourceGroupName $ResourceGroupName -Name $resourceName `
-PropertyObject $properties `
-Force
}
catch {
Write-Error -Message $_.Exception
throw $_.Exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.