#Azure #AzurePowerShell #AppService #PowerShell
If you have multiple Azure Subscriptons, when you login you get a default subscription set, so if you try and take any actions on a feature in another subscription you would get a ‘NotFound’ like error. So you need to set the correct subscription.
The old (ASM) way of doing that was to use the publishSettings file which you can download from here, most likly using the Get-AzurePublishSettings cmdlet. Then you would import that file using the Import-AzurePublishSettingsFile and lastly run the Set-AzureSubscription. However, there is a new way which is more focused on ARM.
I wrote some other articles about using Azure PowerShell listed below:
- Moving an Azure App Service
- Deploy an App Service using Azure PowerShell to a Deployment Slot
- How to tell which Azure PowerShell version you are running
- And some otheres here
To set the Subscription in PowerShell so you can run cmdlets against those features, perform the following:
- Login via PowerShell
- Set the current subscription context
Once you complete the above, you will have set the current azure subscription context
Login via PowerShell
I like to use the Windows PowerShell ISE console app because I find it more friendly, but choose you own approach. Enter the following command to login your PowerShell to Azure:
This will open a challenge/response window where you can enter your userid and password, use the same credentials that you used when you created the PowerShellResourceGroup in the previous section. Once successfully logged in, you will see some output similarly to that shown in Figure 1.
Figure 1, Login to the Azure Portal using PowerShell
Confirm that the SubscriptionId shown in the output is the expected SubscriptionId, if not then continue to the next section
Set the current subscription context
To set the current context to a different subscription, execute this command (using your subscription):
Set-AzureRmContext -SubscriptionId "25ec5bae-****-****-****-***********"
As seen in Figure 2.
Figure 2, how to set the Azure subscription using Azure PowerShell
Also, check out this article: Using Azure Resource Manager-Based PowerShell to Manage Azure Web Apps