I recently ran into an issue when trying to restart an Azure App Service from PowerShell. The command to do it is Restart-AzureWebsite, but when I attempted to run it, I got the following error:
“Restart-AzureWebsite : Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your Azure credentials”
I ran the Add-AzureAccount command but I continued to get the same error.
After some digging I realized that I had more than 1 Azure subscription and the command was using the wrong one when attempting to restart the website.
I ran the following command to retrieve the subscriptions that are cached on my PC:
That returns all of the subscriptions for all of the accounts that you’ve added from Azure. I found the subscription that was correct for the website I was attempting to restart and then ran this command:
Select-AzureSubscription -SubscriptionName "MySubscription"
That set the subscription for the current session to the one that contained the website I needed to restart. From there, everything went smoothly.