PwshAzCosmosDB is a PowerShell binary module built using .NET Core and designed to work with PowerShell Core. It provides cmdlets, written in C#, for performing document-level operations against Azure Cosmos DB. This module is designed to fill the gap left by the lack of document-level operations in the existing Az.CosmosDB module.
PwshAzCosmosDB
depends on the following NuGet packages:
- Azure.Identity (Version 1.10.0)
- Microsoft.Azure.Cosmos (Version 3.35.3)
- PowerShellStandard.Library (Version 7.0.0-preview.1)
- dnMerge (Version 0.5.15)
Note that the dnMerge
package is used to merge multiple NuGet packages into a single assembly to improve module compatibility.
To install the PwshAzCosmosDB module, you can use the PowerShell Gallery:
Install-Module -Name PwshAzCosmosDB -Scope CurrentUser -verbose
PwshAzCosmosDB
provides cmdlets for various document-level operations, including creating, reading, updating, and deleting documents in Azure Cosmos DB.
first you need to connect to the Azure CosmosDB
$params = @{
"Endpoint" = "https://<CosmosDB-Name>.documents.azure.com:443/"
"DatabaseName" = "<DB-Name>"
"ContainerName" = "<Container-Name>"
"MasterKey" = "<Master-Key>"
"Verbose" = $true
}
Connect-AzCosmosDB @params
$env:MANAGED_IDENTITY_CLIENT_ID = '<user-assigned-managed-identity-client-id'
$params = @{
"Endpoint" = "https://<CosmosDB-Name>.documents.azure.com:443/"
"DatabaseName" = "<DB-Name>"
"ContainerName" = "<Container-Name>"
"Verbose" = $true
}
Connect-AzCosmosDB @params
Get-AzCosmosDBDocument -DocumentId "document-id" -PartitionKey "<PartitionKeyValue>" -verbose
$pkField = '<partition-key-field-name>'
$pkValue = '<partition-key-value>'
$documentHashtable = @{
"title" = "New Title"
"description" = "This is a new document"
"author" = "Roberto Rodriguez"
}
New-AzCosmosDBDocument -Document $documentHashTable -PartitionKeyField $pkField -PartitionKeyValue $pkValue -verbose
$documentId = '<document-id>'
$pkField = '<partition-key-field-name>'
$pkValue = '<partition-key-value>'
$updatesHashtable = @{
"testField" = "testvalue"
}
Update-AzCosmosDBDocument -DocumentId $documentId -Updates $updatesHashtable -PartitionKeyField $pkField -PartitionKeyValue $pkValue -verbose
Remove-AzCosmosDBDocument -DocumentId "document-id" -PartitionKey "<PartitionKeyValue>" -verbose
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.