Feel free to create issues if you find any. Or request which command you need me to add next, as this library will be filled out sporadically.
Clone the codebase
git clone https://github.com/bytejunkie/pscosmosdb
Import the module
import-module .\PSCosmosDB.psm1 -force -verbose
setup some variables
# the accountName used for the Cosmos DB account.
$accountName = "bytejunkie"
# The ReadWrite access key if you need to make changes or add to.
$primaryAccessKey = "weflnweflwef/.wecwef./wfwef/=="
You should use a config file if you want the tests to run. Create a file called config.json in the tests folder. The config file will take on of two formats.
{
"emulatorAddress": "https://192.168.1.1:8080/",
"primaryAccessKey": "CX2lwneflwenfwelnflweknfls .adma.skdad=="
}
These details are given out by the emulator when it starts up. Dont forget to import the cert. More info on the emulator Cosmos DB Emulator
{
"accountName": "cosmosdb001",
"resourceGroupName": "CosmosDBRGR001"
}
query away...
Get-CosmosDatabases -AccountName $accountName -PrimaryAccessKey $primaryAccessKey
Get-CosmosDatabases -AccountName $accountName -PrimaryAccessKey $primaryAccessKey -dbName $dbName
New-CosmosDBDatabase -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-NewDBName <insert_db_name_here>
Get-CosmosDBCollections -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here>
Get-CosmosDBCollections -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-collectionName <insert_collection_name_here>
New-CosmosDBCollection -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-newCollectionName <insert_collection_name_here> `
-xmsofferthroughput <insert_offer_throughput_here>
Get-CosmosDBDocuments -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-CollectionName <insert_collection_name_here> `
-xmsmaxitemcount <insert_max_item_count_here>
Get-CosmosDBDocuments -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-CollectionName <insert_collection_name_here> `
-documentId <insert_documentId_here>
New-CosmosDBDocument -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-CollectionName <insert_collection_name_here> `
-xmsmaxitemcount <insert_max_item_count_here> `
-Document <insert_JSON_document_here>
# List all users
Get-CosmosDBDatabaseUser -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
#List single user with more info
Get-CosmosDBDatabaseUser -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> -moreinfo
New-CosmosDBDatabaseUser -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> -moreinfo
Remove-CosmosDBDatabaseUser -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> -moreinfo
# List all permissions, with more info
Get-CosmosDBUserPermission -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> -moreinfo
# List a specific permission against a specific user, or return $false
Get-CosmosDBUserPermission -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> `
-PermissionId <insert_permission_id>
New-CosmosDBUserPermission -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> `
-PermissionId <insert_permission_id> `
-PermissionMode <insert_permission_id> `
-PermissionResourceName <insert_permission_id>
Remove-CosmosDBUserPermission -AccountName $accountName -PrimaryAccessKey $primaryAccessKey `
-DBName <insert_db_name_here> `
-User <insert_username> `
-PermissionId <insert_permission_id>