Created
March 2, 2016 21:52
-
-
Save babo/16b8e86486a3f40df104 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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