Buat daftar dan dapatkan ruang kunci dan tabel untuk Azure Cosmos DB - Cassandra API

BERLAKU UNTUK: Cassandra API

Catatan

Artikel ini menggunakan modul Azure Az PowerShell, yang merupakan modul PowerShell yang direkomendasikan untuk berinteraksi dengan Azure. Untuk mulai menggunakan modul Az PowerShell, lihat Menginstal Azure PowerShell. Untuk mempelajari cara bermigrasi ke modul Az PowerShell, lihat Memigrasikan Azure PowerShell dari AzureRM ke Az.

Sampel ini memerlukan Azure PowerShell Az 5.4.0 atau yang lebih baru. Jalankan Get-Module -ListAvailable Az untuk melihat versi mana yang dipasang. Jika Anda perlu memasang, lihat Pasang modul Azure PowerShell.

Jalankan Connect-AzAccount untuk masuk ke Azure.

Skrip sampel

# 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

Membersihkan penyebaran

Setelah sampel skrip dijalankan, perintah berikut dapat digunakan untuk menghapus grup sumber daya dan semua sumber daya yang terkait.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Penjelasan skrip

Skrip ini menggunakan perintah berikut. Setiap perintah dalam tabel menautkan ke dokumentasi perintah tertentu.

Perintah Catatan
Azure Cosmos DB
Get-AzCosmosDBAccount Mendaftarkan Akun DB Cosmos, atau mendapatkan Akun Cosmos DB tertentu.
Get-AzCosmosDBCassandraKeyspace Mencantumkan Cosmos DB Cassandra API di Akun, atau mendapatkan Ruang Kunci API Cosmos DB Cassandra tertentu di Akun.
Get-AzCosmosDBCassandraTable Mencantumkan Tabel Cosmos DB Cassandra API di Keyspace, atau mendapatkan Tabel Cosmos DB Cassandra API tertentu di Keyspace.
Grup Sumber Daya Azure
Remove-AzResourceGroup Menghapus grup sumber daya termasuk semua sumber daya berlapis.

Langkah berikutnya

Untuk informasi selengkapnya tentang Azure PowerShell, lihat dokumentasi Azure PowerShell.