Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, June 3, 2019 2:01 PM
Hello,
I need to get some statistics about our Azure usage related to allocated VMs. I can count number of them, what type are they etc using az cli comand but ... is there any quicker way to get those statistics across several subscriptions ?
All replies (7)
Monday, June 3, 2019 2:32 PM
Hi,
Here is the PowerShell script that I wrote which will help you.
$rmvms=Get-AzVM
$WarningPreference = 'SilentlyContinue'
foreach ($vm in $rmvms)
{
$WarningPreference = 'SilentlyContinue'
$ps=Get-AzVM `
-ResourceGroupName $vm.ResourceGroupName `
-Name $vm.Name
#You can get the details what you needed by just $ps.NetworkProfile , $ps.OSProfile
}
$rmvms.Count
Regards,
Msrini
Monday, June 3, 2019 2:38 PM
Does that work across subscriptions ?
Monday, June 3, 2019 2:42 PM
Connect-AzureRmAccount
$SubID = Read-Host -Prompt 'Enter your SubID'
Select-AzureRmSubscription -Subscriptionid $SubID
You can use this commands to pass different subscription and get the required details.
Regards,
Msrini
Monday, June 3, 2019 2:45 PM
Oh I see ! (sorry for my ignorance - I don't know powershell ...) it would need to be non-interactive: do it always for all subscriptions I have access to.
That is power shell based - is there any way I can create interactively queries ?
Monday, June 3, 2019 2:49 PM
The script which I shared is PowerShell based.
You can create a excel where you can list your subscriptions and then you can pull in the info from the PS to automate this even further.
Regards,
Msrini
Tuesday, June 4, 2019 4:44 AM
Hi,
Let me know if the above solution helped you.
Please 'Mark as answer' if any of the replies helped, so that others in the community who are looking for similar question, can benefit from it.
Regards,
Msrini
Sunday, June 9, 2019 1:02 PM
Hi,
Do you have any update for me on this thread?
Please 'Mark as answer' if any of the replies helped, so that others in the community who are looking for similar question, can benefit from it.
Regards,
Msrini