Welcome to Microsoft Q&A Forum, thank you for posting your query here!
Please follow below instructions this will resolve your issue.
- Please enable managed identity of your automation account keep it On
- Once you have enabled provide this managed identity copy paste the identity in IAM and provide that identity with contributor access find the below screenshot, please provide it to the appropriate managed identity
- Please add the below script before you run any commands
#Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
My example i have used get-azvm you can use whatever the commands you want to, please find the below output screenshot for azvm
let us know if you have any further queries. I’m happy to assist you further.
Please provide your valuable comments
Please do not forget to "Accept the answer” wherever the information provided helps you, this can be beneficial to other community members.