Skip to content

Instantly share code, notes, and snippets.

@lawrencegripper
Created March 7, 2017 13:37
Show Gist options
  • Select an option

  • Save lawrencegripper/67392170baeb8e1801299cc7018dbf1b to your computer and use it in GitHub Desktop.

Select an option

Save lawrencegripper/67392170baeb8e1801299cc7018dbf1b to your computer and use it in GitHub Desktop.
Uses docdb rest api from powershell to list the collections
$InstanceUrl = "https://something.documents.azure.com:443"
$DatabaseName = "dbname"
$AccessKey = "accesskey"
#Create a signiture for docdb in powershell
function Get-Signature {
param(
[parameter(Mandatory=$true)]
[string]$verb,
[parameter(Mandatory=$true)]
[string]$resourceType,
[parameter(Mandatory=$true)]
[string]$resourceLink,
[parameter(Mandatory=$true)]
[string]$dateString
)
$authHeader = "$verb`n$resourceType`n$resourceLink`n$dateString`n`n"
write-host $authHeader
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Convert]::FromBase64String($AccessKey)
$signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($authHeader))
$signature = [Convert]::ToBase64String($signature)
$headerRaw = "type=master&ver=1.0&sig=$signature"
return [System.Web.HttpUtility]::UrlEncode($headerRaw)
}
$dateString = (Get-Date -Format R).ToLowerInvariant()
$header = Get-Signature "get" "colls" "dbs/$DatabaseName" $dateString
$collections = Invoke-WebRequest -Uri "$InstanceUrl/dbs/$DatabaseName/colls" -Headers @{
"Authorization" = $header
"x-ms-version" = "2015-12-16"
"x-ms-date" = $dateString
} | ConvertFrom-Json
$collections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment