Lista och hämta nyckelområden och tabeller för Azure Cosmos DB – API för Cassandra
GÄLLER FÖR: Kassandra
Kommentar
Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Se Installera Azure PowerShell för att komma igång. Information om hur du migrerar till Az PowerShell-modulen finns i artikeln om att migrera Azure PowerShell från AzureRM till Az.
Det här exemplet kräver Azure PowerShell Az 5.4.0 eller senare. Kör Get-Module -ListAvailable Az
för att se vilka versioner som är installerade.
Om du behöver installera kan du läsa Installera Azure PowerShell-modulen.
Kör Connect-AzAccount för att logga in på Azure.
Exempelskript
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Show list and get operations for accounts, keyspaces, and tables
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$keyspaceName = "mykeyspace"
$tableName = "mytable"
# --------------------------------------------------
Write-Host "List all accounts in a resource group"
Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName
Write-Host "Get an account in a resource group"
Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `
-Name $accountName
Write-Host "List all keyspaces in an account"
Get-AzCosmosDBCassandraKeyspace -ResourceGroupName $resourceGroupName `
-AccountName $accountName
Write-Host "Get a keyspace in an account"
Get-AzCosmosDBCassandraKeyspace -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $keyspaceName
Write-Host "List all tables in a keyspace"
Get-AzCosmosDBCassandraTable -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName
Write-Host "Get a table in a keyspace"
Get-AzCosmosDBCassandraTable -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName `
-Name $tableName
Rensa distribution
När skriptexemplet har körts kan följande kommando användas för att ta bort resursgruppen och alla resurser som är kopplade till den.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Förklaring av skript
Det här skriptet använder följande kommandon. Varje kommando i tabellen länkar till kommandospecifik dokumentation.
Command | Kommentar |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBAccount | Visar en lista över Azure Cosmos DB-konton eller hämtar ett angivet Azure Cosmos DB-konto. |
Get-AzCosmosDBCassandraKeyspace | Visar en lista över Azure Cosmos DB för Apache Cassandra-nyckelytor i ett konto eller hämtar en angiven Azure Cosmos DB för Apache Cassandra Keyspace i ett konto. |
Get-AzCosmosDBCassandraTable | Visar en lista över Azure Cosmos DB för Apache Cassandra-tabeller i en nyckelrymd eller hämtar en angiven Azure Cosmos DB för Apache Cassandra-tabellen i ett nyckelområde. |
Azure-resursgrupper | |
Remove-AzResourceGroup | Tar bort en resursgrupp, inklusive alla kapslade resurser. |
Nästa steg
Mer information om Azure PowerShell finns i Azure PowerShell-dokumentationen.