Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (38 sloc) 1.71 KB
Script provided as is. Use at own risk. No guarantees or warranty provided.
Description - Script designed to login to Azure resources
Source -
Prerequisites = 1
1. Ensure azurerm module installed or updated
ensure that install-az msonline has been run
ensure that update-az msonline has been run to get latest module
Allow custom scripts to run just for this instance
set-executionpolicy -executionpolicy bypass -scope currentuser -force
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$errormessagecolor = "red"
$warnmessagecolor = "yellow"
write-host -foregroundcolor $systemmessagecolor "Script started`n"
write-host -foregroundcolor $processmessagecolor "Azure PowerShell module loading...."
Import-module az
write-host -foregroundcolor $processmessagecolor "Azure PowerShell module loaded"
## Select ARM account
$subscription = get-azsubscription
if ($subscription.count -lt 2) {
## See if there are multiple subscriptions in tenant
## Only one subscription in tenant so set this as default
Set-AzContext -SubscriptionID $subscription
else {
# More than one subscription, set the first one as current
write-host -foregroundcolor $processmessagecolor $subscription.count, "subscriptions detected."
write-host -foregroundcolor $warnmessagecolor "Selecting subscription = ", $[0]
Set-AzContext -SubscriptionID $subscription.Id[0]
## Select-AzureSubscription -SubscriptionID $subscription.Id[0] –Default
## Get-AzureSubscription -SubscriptionDataFile "C:\Temp\MySubscriptions.xml
write-host -foregroundcolor $systemmessagecolor "Script finished"
You can’t perform that action at this time.