Microsoft Azure - Working with PowerShell in Cosmos DB
Last Updated :
26 Jan, 2021
Azure Cosmos DB is a fully managed NoSQL database for build applications designed by Microsoft. It is highly responsive, scalable, and fully automated. Azure Cloud Shell is an in-browser terminal used to manage cloud instances in Azure. The PowerShell is an application used for the same purpose but is installed locally.
In this article, we will look into Azure Cosmos DB with PowerShell where we will create a new Cosmos DB account, a database, and a container with PowerShell. Here we'll use the Azure Cloud Shell, and you can also use a local installation of PowerShell.Some of the operations that you can perform using PowerShell in Cosmos DB are listed below:
- Create a Cosmos DB database
- Update Cosmos DB database
- Delete Cosmos DB database
To create a Cosmos DB database with Powershell/ Cloud Shell follow the below steps:
- Step 1: Before we can start, we need to install the Cosmos DB PowerShell module like with the below command:
Install-Module -Name Az.CosmosDB
At the end of the installation you need to verify again if to install the same as shown below:

- Step 2: First, to see if it works, we will run the below command to list all Cosmos DB accounts in this resource group:
Get-AzCosmosDBAccount -ResourceGroupName "RESOURCE NAME"
This will list the accounts as shown below:
And we can see that there is one in this resource group.
- Step 3: Now, let's create a new Azure Cosmos DB account. This will contain a database that will contain containers with documents in it. This will be an account that uses the SQL API to work with data. This can take a while. At this stage, the Cosmos DB account is created.
- Step 4: Now we need a database for the account. To do so use the below command:
New-AzCosmosDBSqlDatabase
It would result in something like below after completion:
This creates a database, and it is done.
- Step 5: Now, we can add a container to the database with the below command:
New-AzCosmosDBSqlContainer
This will result in the following:
You can create multiple containers in a database, and this one would use the Autoscale feature as shown in the above image:
$ autoscaleMaxThroughput = 4000 #minimum = 4000
Now let's go to the Azure portal to look at the result. We are in the Azure Cosmos DB account in the Data Explorer. Here is the database, and under that is the container.
It also has autoscale enabled.
We've used PowerShell to list Azure Cosmos DB accounts and create a new one with a database and autoscale container.
Similar Reads
How to Install and Connect to Azure AD with PowerShell? Azure Active Directory (Azure AD) is a service for managing identities and access in the cloud. This solution facilitates access to thousands of additional SaaS applications, the Azure portal, and external resources like Microsoft 365 for your staff members. What is Azure Active Directory (AD)?Azure
4 min read
How to Setup Azure Cosmos DB? Azure Cosmos DB is a managed database service that provides high availability and scalability to applications. It provides support for various NoSQL databases. It is available in cross regions hence providing high throughput. In this article, we will set up Azure cosmos DB for NoSQL. So let's see ho
3 min read
Microsoft Azure - Notebooks in Cosmos DB In this article we will learn about how to use Azure Cosmos DB built-in notebooks. So, the easiest way to get started is from the data explorer. You can go to the gallery tab, and so you have official samples written by the Cosmos DB team as well as samples submitted by users in the public gallery.
5 min read
Working with Azure Cosmos DB and JavaScript SDK Azure Cosmos DB is a No SQL database service that supports flexible schemas and hierarchical data for modern applications. It is a globally distributed, multi-model database service that supports document, key-value, wide-column, and graph databases. Azure Cosmos DB service takes care of database ad
10 min read
Microsoft Azure - Using C# in CosmoDB In this article, we will look into how to use C# notebooks in Azure Cosmos DB. When you are creating an application that uses Azure Cosmos DB, it is useful to experiment with code that uses that Cosmos DB. In Azure Cosmos DB, you can use C# notebooks that enable you to write the C# code that interac
3 min read
Microsoft Azure - Using PowerShell Core on Linux PowerShell Core on Linux is now integrated into Azure Cloud Shell. PowerShell used to be only available on Windows. Now, with PowerShell Core, it is cross-platform and runs on macOS and lots of Linux distributions like Ubuntu and Red Hat on ARM-Based platforms and even on Windows. This allows you to
3 min read
How To Install and Update Azure PowerShell on Windows Machine? Pre-requisite: Azure Azure PowerShell is a command-line tool that allows you to manage Azure resources from the command line. It is a powerful tool that can be used to automate tasks, provision resources, manage users and policies in Azure a,d also for troubleshooting problems. Actually, Azure Power
3 min read
How To Use Azure Cosmos DB To Create And Manage NoSQL Databases Azure Cosmos DB is a multi-model, globally distributed database service provided by Microsoft Azure. It comes as a fully managed database service with turnkey global distribution and transparent multi-master replication. You can run globally distributed, low-latency operational and analytics words a
4 min read
How to Upgrade PowerShell in Windows Upgrading PowerShell on Windows ensures access to new commands, enhanced security features, and better compatibility with modern scripts and tools. Whether youâre using it for system administration, automation, or development, staying up to date can make a significant difference.In this guide, weâll
6 min read
Microsoft Azure - Manage Azure VMs using Azure PowerShell Commands Here we are using Azure PS Commands to manage azure resources from Azure Cloud Shell or by using Windows PowerShell. By using the simple AZ PS command we can manage Azure VM Quicks without any efforts of navigating in Azure Portal and at Scale. Let's get started by using the major Azure PS commands
2 min read