Skip to content

Instantly share code, notes, and snippets.

@masimplo
Last active August 29, 2015 14:22
Show Gist options
  • Save masimplo/9b978ac4dbd343b5a851 to your computer and use it in GitHub Desktop.
Save masimplo/9b978ac4dbd343b5a851 to your computer and use it in GitHub Desktop.
Create azure management certificate and add it to CurrentUser storage
<#
.SYNOPSIS
Sets the specified Windows Azure Subscription as the current context
.DESCRIPTION
First creates/updates the subscription profile
Checks the required management certificate is installed
Sets the subscription context for all WAZ cmdlets used in the session
.EXAMPLE
Set-AzureSubscriptionContext -SubscriptionName “MySubscription” -SubscriptionId “00000000-0000-0000-0000-000000000000″ -CertificateThumbprint “00000000000000000000000000000000000000000”
.OUTPUTS
None
#>
function Set-AzureSubscriptionContext
{
param
(
# Windows Azure Subscription Name
[Parameter(Mandatory = $true)]
[String]
$SubscriptionName,
# Windows Azure Subscription Id
[Parameter(Mandatory = $true)]
[String]
$SubscriptionId,
# Management Certificate thumbnail
[Parameter(Mandatory = $true)]
[String]
$CertificateThumbprint
)
# Get management certificate from personal store
$certificate = Get-Item cert:\\CurrentUser\My\$CertificateThumbprint
if ($certificate -eq $null) {
throw “Management certificate for $SubscriptionName was not found in the users personal certificate store. Check thumbprint or install certificate”
}
# Set subscription profile
Set-AzureSubscription -SubscriptionName $SubscriptionName -SubscriptionId $SubscriptionId -Certificate $certificate
# Select subscription as the current context
Select-AzureSubscription -SubscriptionName $SubscriptionName
}
makecert -r -pe -a sha1 -n CN=AzureMgmt -ss My “AzureMgmt.cer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment