Share via


PowerShell-skript för att lista eller hämta Azure Cosmos DB för Gremlin-databaser och grafer

GÄLLER FÖR: Gremlin

Det här PowerShell-skriptet visar eller hämtar specifika Azure Cosmos DB-konton, API för Gremlin-databaser och API för Gremlin-grafer.

Anteckning

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.

Förutsättningar

  • 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 modul.

  • Kör Connect-AzAccount för att logga in på Azure.

Exempelskript

I det här skriptet:

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# List and get operations for accounts, databases, and graphs
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$graphName = "myGraph"
# --------------------------------------------------

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 databases in an account"
Get-AzCosmosDBGremlinDatabase -ResourceGroupName $resourceGroupName `
    -AccountName $accountName

Write-Host "Get a database in an account"
Get-AzCosmosDBGremlinDatabase -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $databaseName

Write-Host "List all graphs in a database"
Get-AzCosmosDBGremlinGraph -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -DatabaseName $databaseName 

Write-Host "Get a graph in a database"
Get-AzCosmosDBGremlinGraph -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -DatabaseName $databaseName `
    -Name $graphName

Ta bort Azure-resursgrupp

Om du vill ta bort ditt Azure Cosmos DB-konto kan du ta bort resursgruppen med powershell-kommandot Remove-AzResourceGroup . Det här kommandot tar bort Azure-resursgruppen och alla resurser i den, inklusive Azure Cosmos DB-konton och deras containrar och databaser.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Nästa steg

Mer information om Azure PowerShell finns i Azure PowerShell-dokumentationen.