azurepowershellenterprise

Azure Powershell - across MULTIPLE subscriptions in an EA


I have "billing reader" access to several hundred subscriptions in an EA.

I'm trying to get a list of virtual machines and their sizes across all subscriptions.

So currently when I run a "Get-AzureRMSubscription" it shows me all the subscriptions (hundreds of them), but i'm not sure how to actually run a script against all the subscriptions?

Would be great to get a "Get-AzureRMVM" across them all

Any suggestions? Thanks in advance!


Solution

  • You can possibly do something like this:

    $azureSubs = Get-AzureRMSubscription
    $azureSubs | ForEach-Object {Select-AzureRMSubscription $_ | Out-Null; Get-AzureRMVM -WarningAction SilentlyContinue}
    

    You are essentially setting an array variable to hold all your Azure Subscription and piping it to the ForEach-Object cmdlet to iterate all of the objects in the array. Then you pipe it to the Get-AzureRMVM cmdlet to list all VMs in each subscription.

    This is definitely not optimized for performance and there might be better solutions out there, but at least you can run it and forget it.

    The reason for the Out-Null and -WarningAction is to suppress the outputs you do not need.