Forum Discussion

Sean145's avatar
Sean145
Copper Contributor
Dec 24, 2024

find the azure vm status in multiple subscription

We have multiple subscription (more than 10) in our environment and MFA enabled ,  I was trying to find one vm status using the name but its not working , setting azcontext with tenant ID also not working ,

I need command to set all subscription as context and find the vm status or any other way to find the vm status , this is needed for daily work, appreciate someone help on this . 

 

1 Reply

  • luchete's avatar
    luchete
    Iron Contributor

    To manage VMs across multiple subscriptions, you need to first ensure you're authenticated and have access to all the subscriptions. You can use the Set-AzContext command to switch between them, but for querying across multiple subscriptions in a script, you can loop through all subscriptions using Get-AzSubscription and Set-AzContext within a script. Once the context is set for each subscription, you can use Get-AzVM to check the VM status. Make sure your account has sufficient permissions on each subscription and that MFA isn't blocking your access, otherwise you'll receive an error.

    Hope it helps!

Resources