Skip to content

Instantly share code, notes, and snippets.

@codingoutloud
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save codingoutloud/f3c74eeceb84f2f7ae15 to your computer and use it in GitHub Desktop.

Select an option

Save codingoutloud/f3c74eeceb84f2f7ae15 to your computer and use it in GitHub Desktop.
Formats the output from Get-AzureStorageKey as a connection string.
Function Format-AzureStorageKey {
[CmdletBinding()]
Param (
[parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True)]
[string[]] $Primary,
[parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True)]
[string[]] $Secondary,
[parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True)]
[string[]] $StorageAccountName,
[switch] $AsConnectionString, # noop since is really only current option
[switch] $UseSecondary,
[switch] $UseHttp
# Not providing UsePrimary or UseHttps switches since they are defaults
# Consider adding support for proxies and specific services:
# http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx
)
if ($UseSecondary) {
$key = $Secondary
}
else {
$key = $Primary
}
if ($UseHttp) {
$protocol = "http"
}
else {
$protocol = "https"
}
Write-Host "DefaultEndpointsProtocol=$protocol;AccountName=$StorageAccountName;AccountKey=$key"
}
@codingoutloud

Copy link
Copy Markdown
Author

Usage Setup:

  • make sure you have an active cert or logged in account, e.g.: Add-AzureAccount
  • make sure you have selected a subscription within that account with an available storage account - in the Usage section below, that account is 'pragazdiags' which you would replace with your own

Usage:

  • Get-AzureStorageKey -StorageAccountName pragazdiags | Format-AzureStorageKey
  • Get-AzureStorageKey -StorageAccountName pragazdiags | Format-AzureStorageKey -AsConnectionString
  • Get-AzureStorageKey -StorageAccountName pragazdiags | Format-AzureStorageKey -UseSecondary -UseHttp

Output:

  • DefaultEndpointsProtocol=https;AccountName=pragazdiags;AccountKey=9+RvXH9SeYuDyueyAtzqQ
    bcE52sidWQbCXoxidpn6ZROL20GFVj+Ulc3X7+GbemcWOlYK6sUycAJJqmJaQ0KnQ==
  • DefaultEndpointsProtocol=https;AccountName=pragazdiags;AccountKey=9+RvXH9SeYuDyueyAtzqQ
    bcE52sidWQbCXoxidpn6ZROL20GFVj+Ulc3X7+GbemcWOlYK6sUycAJJqmJaQ0KnQ==
  • DefaultEndpointsProtocol=http;AccountName=pragazdiags;AccountKey=TUzONza19iYiZvqU12W9bj
    Z/blgG9lygTIKCBXeT3q8K6RaXCC0Xqrm3M3zm6+SiULrY+dbFdTyOl+KmsHqcJg==

Resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment