Skip to content

Instantly share code, notes, and snippets.

@PaulNichols
Last active February 2, 2018 05:57
Show Gist options
  • Save PaulNichols/4b1c557787bf1b35ba0968d8b9864bf1 to your computer and use it in GitHub Desktop.
Save PaulNichols/4b1c557787bf1b35ba0968d8b9864bf1 to your computer and use it in GitHub Desktop.
Azure login
# You may need to install the Azure RM module first
# https://github.com/Azure/azure-powershell/releases
# Install-Module -Name AzureRM -Repository PSGallery -Force
$writeHostForeColour="magenta"
write-host "Logging in to Azure..." -foregroundcolor $writeHostForeColour
Login-AzureRmAccount
$subscriptions=Get-AzureRMSubscription
write-host
write-host "Which Subscription would you like to deploy the ARM templates to?" -foregroundcolor $writeHostForeColour
$idx=0
$subIds = @()
$subNames = @()
foreach ($sub in $subscriptions) {
$state=$sub.State
if ($state -eq "Enabled")
{
$name=$sub.Name
write-host "[$idx] $name" -foregroundcolor $writeHostForeColour
$idx=$idx+1
$subIds += $sub.Id
$subNames += $name
}
}
$chosenSubIndex=Read-Host
write-host "Saving..." -foregroundcolor $writeHostForeColour
$chosenSubName= $subNames[$chosenSubIndex]
$chosenSubId=$subIds[$chosenSubIndex]
$x=Get-AzureRMSubscription -SubscriptionId $chosenSubId | Set-AzureRMContext
write-host "Ok that choice '$chosenSubName' has been saved to make logging in to Azure quicker next time" -foregroundcolor $writeHostForeColour
Save-AzureRmContext -Path .\ProfileContext.ctx -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment