Skip to content

Instantly share code, notes, and snippets.

@dalibormesaric
Created October 27, 2019 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalibormesaric/2d9014ff3eba0b7261a557d7a1ff23ac to your computer and use it in GitHub Desktop.
Save dalibormesaric/2d9014ff3eba0b7261a557d7a1ff23ac to your computer and use it in GitHub Desktop.
$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