Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Parameters
- $clientId= "XXXXXXXXXXXXXXX"
- $clientSecret= "XXXXXXXXXXXX="
- $subscriptionName= "XXXXXXXXXXXXXXX"
- $tenantId= "XXXXXXXXXXXXXXXX"
- $resourceGroupName= "Demo"
- $connectionString='XXXXXXXXXXXXXXXXx=='
- $cosmosDBAccounts= @('demo-account-01')
- $databaseName='demo-db-01'
- $collectionName='demo-collection-01'
- $partitionkey= 'demo'
- #endregion
- #region Login into Azure using Interactive Mode or Service Principal details
- # sign in
- Write-Host "Logging in...";
- #Connect-AzAccount
- $securePassword = $clientSecret | ConvertTo-SecureString -AsPlainText -Force
- $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $clientId, $securePassword
- Connect-AzAccount -Credential $cred -ServicePrincipal -TenantId $tenantId
- #Set the current azure subscription
- Select-AzSubscription -subscription $subscriptionName
- #endregion
- #region Create Collection and insert some data into it
- foreach($cosmosDBAccount in $cosmosDBAccounts){
- $key = Get-CosmosDbAccountMasterKey -Name $cosmosDBAccount -ResourceGroupName $resourceGroupName
- $cosmosDbContext = New-CosmosDbContext -Account $cosmosDBAccount -Key $key
- New-CosmosDbDatabase -Context $cosmosDbContext -Id $databaseName
- New-CosmosDbCollection -Context $cosmosDbContext -Id $collectionName -PartitionKey $partitionkey -OfferThroughput 2500 -Database $databaseName
- 0..9 | Foreach-Object {
- $document = @"
- {
- `"id`": `"$([Guid]::NewGuid().ToString())`",
- `"name`": `"pradeep`"
- }
- "@
- New-CosmosDbDocument -Context $cosmosDbContext -CollectionId $collectionName -DocumentBody $document -PartitionKey $partitionkey
- }
- }
- #endregion
Add Comment
Please, Sign In to add comment