This sample requires Azure PowerShell Az 5.4.0 or later. Run Get-Module -ListAvailable Az to see which versions are installed.
If you need to install, see Install Azure PowerShell module.
You cannot modify regions and change other Azure Cosmos DB account properties in the same operation. These must be done as two separate operations.
Note
This sample demonstrates using a API for NoSQL account. To use this sample for other APIs, copy the related properties and apply to your API-specific script.
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update Cosmos DB account: Change default consistency level
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$consistencyLevel = "BoundedStaleness"
$maxStalenessInterval = 300
$maxStalenessPrefix = 100000
# --------------------------------------------------
# Get existing Cosmos DB account
$account = Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName -Name $accountName
Write-Host "Updating account $accountName"
Update-AzCosmosDBAccount -InputObject $account `
-DefaultConsistencyLevel $consistencyLevel `
-MaxStalenessIntervalInSeconds $maxStalenessInterval `
-MaxStalenessPrefix $maxStalenessPrefix
Clean up deployment
After the script sample has been run, the following command can be used to remove the resource group and all resources associated with it.