Hello Andrea,
Greetings! Welcome to Microsoft Q&A Forum.
I understand that you are encountering an issue with your Azure Automation runbook in PowerShell. As per the error message no subscription was found in the current session of your PowerShell function.
"No subscription found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Connect-AzAccount to login"
Ensure you have met the Prerequisites:
· Install the Azure PowerShell module in your Azure Automation account.
· Assign necessary roles (e.g., Storage Blob Data Contributor) to the managed identity or service principal.
Reference Links:
- https://video2.skills-academy.com/en-us/azure/automation/create-run-as-account
- https://video2.skills-academy.com/en-us/azure/automation/automation-role-based-access-control
- https://video2.skills-academy.com/en-us/azure/automation/shared-resources/variables?tabs=azure-powershell
- https://video2.skills-academy.com/en-us/azure/automation/shared-resources/credentials?tabs=azure-powershell
- https://video2.skills-academy.com/en-us/powershell/azure/authenticate-azureps?view=azps-7.1.0
Most likely the credentials that you are using to login to Azure and use Get-AzureRmVm have expired, no longer valid or no longer available. If you are using the default credentials when Azure Automation account is created in the Automation account check Run as accounts tabs.
Please do let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.