Guest User

Untitled

a guest
Jan 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #region Parameters
  2.  
  3. $clientId= "XXXXXXXXXXXXXXX"
  4. $clientSecret= "XXXXXXXXXXXX="
  5. $subscriptionName= "XXXXXXXXXXXXXXX"
  6. $tenantId= "XXXXXXXXXXXXXXXX"
  7. $resourceGroupName= "Demo"
  8. $connectionString='XXXXXXXXXXXXXXXXx=='
  9. $cosmosDBAccounts= @('demo-account-01')
  10. $databaseName='demo-db-01'
  11. $collectionName='demo-collection-01'
  12. $partitionkey= 'demo'
  13.  
  14. #endregion
  15.  
  16. #region Login into Azure using Interactive Mode or Service Principal details
  17.  
  18. # sign in
  19. Write-Host "Logging in...";
  20.  
  21. #Connect-AzAccount
  22. $securePassword = $clientSecret | ConvertTo-SecureString -AsPlainText -Force
  23. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $clientId, $securePassword
  24. Connect-AzAccount -Credential $cred -ServicePrincipal -TenantId $tenantId
  25.  
  26. #Set the current azure subscription
  27. Select-AzSubscription -subscription $subscriptionName
  28.  
  29. #endregion
  30.  
  31. #region Create Collection and insert some data into it
  32.  
  33. foreach($cosmosDBAccount in $cosmosDBAccounts){
  34.  
  35. $key = Get-CosmosDbAccountMasterKey -Name $cosmosDBAccount -ResourceGroupName $resourceGroupName
  36. $cosmosDbContext = New-CosmosDbContext -Account $cosmosDBAccount -Key $key
  37. New-CosmosDbDatabase -Context $cosmosDbContext -Id $databaseName
  38. New-CosmosDbCollection -Context $cosmosDbContext -Id $collectionName -PartitionKey $partitionkey -OfferThroughput 2500 -Database $databaseName
  39. 0..9 | Foreach-Object {
  40.  
  41. $document = @"
  42. {
  43. `"id`": `"$([Guid]::NewGuid().ToString())`",
  44. `"name`": `"pradeep`"
  45. }
  46. "@
  47. New-CosmosDbDocument -Context $cosmosDbContext -CollectionId $collectionName -DocumentBody $document -PartitionKey $partitionkey
  48. }
  49. }
  50.  
  51.  
  52.  
  53. #endregion
Add Comment
Please, Sign In to add comment