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

CmdletDescription
New-AzCosmosDBAccountCreates a new Azure Cosmos DB account.
Get-AzCosmosDBAccountRetrieves details of existing Cosmos DB accounts.
Remove-AzCosmosDBAccountDeletes a Cosmos DB account.
New-AzCosmosDBSqlDatabaseCreates a new SQL API database within an account.
New-AzCosmosDBSqlContainerCreates a new container (collection) in a SQL database.
Get-AzCosmosDBSqlContainerLists containers in a SQL database.
Set-AzCosmosDBAccountUpdates properties of an existing account.
Test-AzCosmosDBConnectionStringValidates 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.

Related Documentation