Share via


Using Subscriptions in PowerShell Scripts

The majority of Azure PowerShell cmdlets interact with Azure Subscriptions, vital for changing or deploying VM's to the subscription. For those customers who have multiple accounts it is essential to ensure the correct one is selected before issuing any commands. Checking which subscriptions have been imported is a matter of using the cmdlet "Get-AzureSubscrption", this will show which is the "Current" subscription. Associating a subscription to your Azure operations is a matter of importing the settings for the account, using the cmdlet "Get-AzurePublishSettingsFile", which fires up your default browser and prompts to download your publishsettingsfile. Opening this up in notepad will present an xml detailing all the subscriptions your Microsoft Account is assigned to. To import this, use the cmdlet "Import-AzurePublishSettingsFile". Be warned though, this file grants access to the subscription, so save in an appropriate location and remove once finished.

 

TIP: Remove all subscriptions in the xml PublishSettingsFile, except the one you want to use and run the following PowerShell cmdlet before importing that file: "Remove-AzureSubscription." that way you can be sure the correct subscription is always used.