Skip to content

Instantly share code, notes, and snippets.

@babo
Created March 2, 2016 21:52
Show Gist options
  • Save babo/16b8e86486a3f40df104 to your computer and use it in GitHub Desktop.
Save babo/16b8e86486a3f40df104 to your computer and use it in GitHub Desktop.
function SelectSubscription () {
$context=$null
try {
$context = Get-AzureRmContext
} catch [ System.Management.Automation.PSInvalidOperationException] {}
if ($context -eq $null) {
$context = (Login-AzureRmAccount).Context
}
$subscription = Get-AzureRmSubscription | Out-GridView -Title "Select Azure Subscription" -PassThru
if ($subscription -eq $null) {
Throw "No subscription selected"
}
Set-AzureRmContext -SubscriptionId $subscription.SubscriptionId
Write-Host "Welcome $($context.Account.Id) at $($subscription.SubscriptionName)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment