In this jumpstart, I am going to show how to connect to a Azure Subscription from a remote machine using PowerShell. This approach is useful when we are trying to automate Azure related deployment and maintenance activities from remote machines.
As a first step download and install last Microsoft Azure PowerShell – May 2015 release. Now open Windows Azure PowerShell console (All Programs –> Azure PowerShell).
Option 1 : Using PublishSettings file
Step 1 : Download and save Azure PublishSettings file by visiting this link on the remote machine.
Step 2 : Run following command.
Import-AzurePublishSettingsFile -PublishSettingsFile C:\Users\venvemula\Desktop\Azure\ramiv.publishsettings
NOTE : A publish settings file contains information about all the Azure subscriptions (including subscriptions where logged-in user is a Co-Administrator) for a specific Azure login. It also contains a management certificate through which a remote machine can be authenticated at Windows Azure Service Management API requests.
In case of multiple subscriptions, we can use following command to set a specific subscription as a context for that on-going PowerShell session.
Select-AzureSubscription -SubscriptionName "Visual Studio Ultimate with MSDN"
To check whether a subscription is set to PowerShell context, we can run following command –
Option 2 : Using Azure PowerShell Cmdlets
Run following command –
It will prompt to enter Azure subscription user name and password. After successful authentication, PowerShell console will list all Azure Subscriptions associated with that login.
We can again use Select-AzureSubscription to associate a subscription to a PowerShell running session.
Using above options a remote machine can connect to a Azure Subscription using PowerShell session and perform numerous Azure Management operations.
Once all the necessary tasks are done, it is always advisable to remove subscription from PowerShell context. To do that run following command –
Remove-AzureSubscription -SubscriptionName "Visual Studio Ultimate with MSDN"