Az.CosmosDB PowerShell Module
Overview
The Az.CosmosDB module provides cmdlets for managing Azure Cosmos DB resources. It enables you to create, configure, and monitor Cosmos DB accounts, databases, containers, and more directly from PowerShell.
Installation
Install-Module -Name Az.CosmosDB -Scope CurrentUser -Repository PSGallery -Force
To upgrade to the latest version:
Update-Module -Name Az.CosmosDB
Key Cmdlets
| Cmdlet | Description | 
|---|---|
| New-AzCosmosDBAccount | Creates a new Azure Cosmos DB account. | 
| Get-AzCosmosDBAccount | Retrieves details of existing Cosmos DB accounts. | 
| Remove-AzCosmosDBAccount | Deletes a Cosmos DB account. | 
| New-AzCosmosDBSqlDatabase | Creates a new SQL API database within an account. | 
| New-AzCosmosDBSqlContainer | Creates a new container (collection) in a SQL database. | 
| Get-AzCosmosDBSqlContainer | Lists containers in a SQL database. | 
| Set-AzCosmosDBAccount | Updates properties of an existing account. | 
| Test-AzCosmosDBConnectionString | Validates a Cosmos DB connection string. | 
Example: Create a Cosmos DB SQL API Account
# Variables $resourceGroup = "MyResourceGroup" $accountName = "mycosmosdbaccount" $location = "EastUS" # Create the account New-AzCosmosDBAccount ` -ResourceGroupName $resourceGroup ` -Name $accountName ` -Location $location ` -ApiKind Sql ` -EnableAutomaticFailover $true ` -ConsistencyPolicyType "Session"
This script creates a new Cosmos DB account with automatic failover and session consistency.