Azure Cosmos DB - Cassandra 用 API のキースペースとテーブルを一覧表示および取得する

適用対象: Cassandra

注意

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

このサンプルには、Azure PowerShell Az 5.4.0 以降が必要です。 Get-Module -ListAvailable Az を実行して、インストールされているバージョンを確認します。 インストールする必要がある場合は、Azure PowerShell モジュールのインストールに関するページを参照してください。

Connect-AzAccount を実行して Azure にサインインします。

サンプル スクリプト

# 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

デプロイのクリーンアップ

スクリプト サンプルの実行後は、次のコマンドを使用してリソース グループとすべての関連リソースを削除することができます。

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

スクリプトの説明

このスクリプトでは、次のコマンドを使用します。 表内の各コマンドは、それぞれのドキュメントにリンクされています。

コマンド Notes
Azure Cosmos DB
Get-AzCosmosDBAccount Azure Cosmos DB アカウントを一覧表示します。または、指定された Azure Cosmos DB アカウントを取得します。
Get-AzCosmosDBCassandraKeyspace アカウント内の Azure Cosmos DB for Apache Cassandra のキースペースを一覧表示するか、アカウント内の指定された Azure Cosmos DB for Apache Cassandra のキースペースを取得します。
Get-AzCosmosDBCassandraTable キースペース内の Azure Cosmos DB for Apache Cassandra テーブルを一覧表示するか、キースペース内の指定された Azure Cosmos DB for Apache Cassandra テーブルを取得します。
Azure リソース グループ
Remove-AzResourceGroup 入れ子になったリソースすべてを含むリソース グループを削除します。

次のステップ

Azure PowerShell の詳細については、Azure PowerShell のドキュメントを参照してください。