Created
October 27, 2019 17:17
-
-
Save dalibormesaric/2d9014ff3eba0b7261a557d7a1ff23ac to your computer and use it in GitHub Desktop.
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
$azExists = Get-InstalledModule Az -AllVersions -ErrorAction SilentlyContinue | |
if ($azExists) { | |
Write-Host "Az PowerShell installed ..." | |
} | |
else { | |
Write-Host "You need Az PowerShell https://docs.microsoft.com/en-us/powershell/azure/" | |
Break | |
} | |
Import-Module Az | |
# https://github.com/Azure/azure-powershell/issues/8628#issuecomment-478644165 | |
$azureContext = Disable-AzContextAutosave -Scope Process | |
Clear-AzContext | |
# Clear-AzContext -Scope CurrentUser -Force # https://github.com/Azure/azure-powershell/issues/8628 | |
$azureAccount = Connect-AzAccount | |
$azureSubscriptions = Get-AzSubscription | |
$azureSubscriptionCounter = 1 | |
foreach ($azureSubscription in $azureSubscriptions) { | |
Write-Output "($azureSubscriptionCounter) $($azureSubscription.Name)" | |
$azureSubscriptionCounter++; | |
} | |
$subscriptionNumber = Read-Host 'Please choose subscription' | |
$subscription = Select-AzSubscription -SubscriptionId $azureSubscriptions[$subscriptionNumber - 1].Id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment