{"id":1486,"date":"2020-06-25T09:00:23","date_gmt":"2020-06-25T16:00:23","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=1486"},"modified":"2020-06-25T13:00:22","modified_gmt":"2020-06-25T20:00:22","slug":"powershell-preview","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/powershell-preview\/","title":{"rendered":"New Azure Cosmos DB PowerShell features for greater enterprise manageability"},"content":{"rendered":"<h2>Enterprise Manageability<\/h2>\n<p>Azure Cosmos DB enterprise manageability and readiness continues to mature, with multiple management libraries available. The <a href=\"https:\/\/www.powershellgallery.com\/packages\/Az.CosmosDB\" target=\"_blank\" rel=\"noopener noreferrer\">Az.CosmosDB PowerShell package<\/a> lets you directly manage Azure Cosmos DB accounts, databases, containers, throughput, and more across all Azure Cosmos DB APIs. Az.CosmosDB is in public preview with General Availability (GA) expected later this year.<\/p>\n<p>In my <a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/manage-with-powershell\/\" target=\"_blank\" rel=\"noopener noreferrer\">previous post about Az.CosmosDB<\/a>, I introduced it and discussed how to start working with it. In this post, I&#8217;ll show some examples for how to work directly with Azure Cosmos DB resources using the PowerShell cmdlets, and I&#8217;ll also note several Az.CosmosDB additions to let customers manage new Azure Cosmos DB capabilities including autoscale, analytical storage, free tier, and MongoDB API Server version.<\/p>\n<p><strong>NOTE<\/strong>: you will need <a href=\"https:\/\/www.powershellgallery.com\/packages\/Az.CosmosDB\" target=\"_blank\" rel=\"noopener noreferrer\">Az.CosmosDB<\/a> 0.1.6 or newer to use the new capabilities discussed below.<\/p>\n<p>&nbsp;<\/p>\n<h2>Manage Azure Cosmos DB Resources using Cmdlets<\/h2>\n<p>The Az.CosmosDB cmdlets enable detailed management of Azure Cosmos DB resources. Below I show you a complete PowerShell script that completes several steps, starting with creation of a new Azure Resource Group with <code>New-AzResourceGroup<\/code>.<\/p>\n<p>Then I use <code>New-AzCosmosDBAccount<\/code> to deploy a new Azure Cosmos DB account configured for Azure Cosmos DB&#8217;s API for MongoDB with compatibility level 3.6 and enabled for analytical store (more on that later in this post). After that, I use <code>New-AzCosmosDBMongoDBDatabase<\/code> to deploy a new database into my new account.<\/p>\n<p>Next, I use <code>New-AzCosmosDBMongoDBIndex<\/code> to create a new unique index definition with the partition keys. This is one of many cmdlets provided in the Az.CosmosDB package for very granular management of Azure Cosmos DB resources and configurations.<\/p>\n<p>Last, I use <code>New-AzCosmosDBMongoDBCollection<\/code> to create a new container in the database with the index I created above and configured to enable analytical store and autoscale (more on that later in this post) to a maximum of 4,000 RU\/s.<\/p>\n<p>https:\/\/gist.github.com\/plzm\/2ec6d0f31089dbbb9eafb64402849e02<\/p>\n<p>&nbsp;<\/p>\n<h2>Autoscale<\/h2>\n<p>Autoscale provisioned throughput is described in <a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/autoscale-serverless-offers\/\" target=\"_blank\" rel=\"noopener noreferrer\">this post<\/a> and the <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/provision-throughput-autoscale\" target=\"_blank\" rel=\"noopener noreferrer\">Azure Cosmos DB documentation<\/a>. Both databases and containers can be configured with autoscale.<\/p>\n<p>The Az.CosmosDB cmdlets for database and container management accept a new parameter, <code>-AutoscaleMaxThroughput<\/code>. For example, to configure a container to autoscale instantly up to a maximum of 4,000 RU\/s:<\/p>\n<p><code>New-AzCosmosDbSqlContainer [...] -AutoscaleMaxThroughput 4000<\/code><\/p>\n<p>You can update the configured autoscale max throughput. For example, to increase the autoscale max throughput from 4,000 to 6,000 RU\/s:<\/p>\n<p><code>Update-AzCosmosDbSqlContainer [...] -AutoscaleMaxThroughput 6000<\/code><\/p>\n<p><strong>NOTE<\/strong>: Use either <code>-AutoscaleMaxThroughput<\/code>(for autoscale throughput) or <code>-Throughput<\/code> (for standard throughput) &#8211; do not use both together.<\/p>\n<p>&nbsp;<\/p>\n<h2>Analytical store<\/h2>\n<p>Azure Cosmos DB analytical store is a component of Azure Synapse Link, described in <a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/announce-azure-synapse-link-no-etl-analytics\/\" target=\"_blank\" rel=\"noopener noreferrer\">this post<\/a> and the <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/analytical-store-introduction\" target=\"_blank\" rel=\"noopener noreferrer\">Azure Cosmos DB documentation<\/a>.<\/p>\n<p>To use Azure Cosmos DB analytical store with Azure Synapse Link, first enable analytical store on a new account using <code>New-AzCosmosDBAccount [...] -EnableAnalyticalStorage $true<\/code>, or on an existing account using <code>Update-AzCosmosDBAccount [...] -EnableAnalyticalStorage $true<\/code>.<\/p>\n<p>Then create new containers with analytical store enabled by using the <code>-AnalyticalStoreTtl<\/code> parameter. Currently, API for MongoDB collections and Cassandra API tables can be enabled for Analytical Store using <code>New-AzCosmosDBMongoDBCollection<\/code> or <code>New-AzCosmosDBCassandraTable<\/code>, and additional Azure Cosmos DB APIs will be supported by GA.<\/p>\n<p>&nbsp;<\/p>\n<h2>MongoDB API &#8211; Set Server Version<\/h2>\n<p><code>New-AzCosmosDBAccount<\/code> now accepts a <code>-ServerVersion<\/code> parameter to specify the MongoDB compatibility level for the new\u00a0 API for MongoDB account. For example: <code>New-AzCosmosDBAccount [...] -ApiKind \"MongoDB\" -ServerVersion \"3.6\"<\/code><\/p>\n<p>&nbsp;<\/p>\n<h2>Enable free tier<\/h2>\n<p>Free tier was introduced on a <a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/running-a-low-cost-scalable-app-with-azure-cosmos-db-free-tier\/\" target=\"_blank\" rel=\"noopener noreferrer\">previous post<\/a>. With free tier, you receive 400 RU\/s throughput and 5 GB storage each month for free for the life of the Azure Cosmos DB account on which it is configured.<\/p>\n<p>Free tier is available for one Azure Cosmos DB account per Azure subscription and must be configured when the Azure Cosmos DB account is created:<\/p>\n<p><code>New-AzCosmosDBAccount [...] -EnableFreeTier $true<\/code><\/p>\n<p>&nbsp;<\/p>\n<h2>More Information<\/h2>\n<p>PowerShell management samples are available for each of the Azure Cosmos DB APIs:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/powershell-samples-sql\" target=\"_blank\" rel=\"noopener noreferrer\">Core (SQL) API samples<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/powershell-samples-mongodb\" target=\"_blank\" rel=\"noopener noreferrer\">API for MongoDB samples<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/powershell-samples-cassandra\" target=\"_blank\" rel=\"noopener noreferrer\">Cassandra API samples<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/powershell-samples-gremlin\" target=\"_blank\" rel=\"noopener noreferrer\">Gremlin API samples<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/powershell-samples-table\" target=\"_blank\" rel=\"noopener noreferrer\">Table API samples<\/a><\/li>\n<\/ul>\n<p>References, source code, and issues:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/manage-with-powershell\" target=\"_blank\" rel=\"noopener noreferrer\">Manage Azure Cosmos DB Core (SQL) API resources using PowerShell<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/powershell\/module\/az.cosmosdb\/\" target=\"_blank\" rel=\"noopener noreferrer\">Az.CosmosDB cmdlet reference<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-powershell\/tree\/master\/src\/CosmosDB\" target=\"_blank\" rel=\"noopener noreferrer\">Az.CosmosDB source code on GitHub<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-powershell\/issues\" target=\"_blank\" rel=\"noopener noreferrer\">Bugs or feature requests on GitHub<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Wrapping Up<\/h2>\n<p>We are excited that Azure Cosmos DB continues to add enterprise manageability capabilities. We hope the ongoing improvements to the Az.CosmosDB management library are helpful as you manage your Azure Cosmos DB resources.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn about the new PowerShell cmdlets available in Az.CosmosDB available now in public preview.<\/p>\n","protected":false},"author":13019,"featured_media":1374,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[12,1460],"tags":[],"class_list":["post-1486","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcements","category-powershell"],"acf":[],"blog_post_summary":"<p>Learn about the new PowerShell cmdlets available in Az.CosmosDB available now in public preview.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/1486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/13019"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=1486"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/1486\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/1374"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=1486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=1486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=1486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}