Last active
August 29, 2015 14:22
-
-
Save masimplo/9b978ac4dbd343b5a851 to your computer and use it in GitHub Desktop.
Create azure management certificate and add it to CurrentUser storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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