Posted  by  admin

Azure Show All Running Resources

  1. Azure Show All Running Resources Free

In this repository All GitHub ↵ Jump to. No cmdlet to get VM status (running, etc) with ARM #1724. ItalyPaleAle opened this issue Jan 27, 2016 19 comments Comments. Another one-liner I use frequently to show me Resource Group, VM Name, and current status.

Track tasks and feature requests

Join 36 million developers who use GitHub issues to help identify, assign, and keep track of the features and bug fixes your projects need.

Sign up for free See pricing for teams and enterprises New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments

commented Jan 27, 2016

A customer of mine reported that Get-AzureRmVM does not include any field specifying whether the VM is running or not, as Get-AzureVM does.

commented Jan 29, 2016

Agreed - this should definitely be more explicit. Current workaround is to use the -Status flag on Get-AzureRmVM. You can then access the Statuses property.

For example:

(get-azurermvm -ResourceGroupName $rgName -Name $vmName -Status).Statuses

commented Jan 29, 2016

Thank you @mjyeaney ! This will do it for now - though I agree it should be made more explicit.

commented Feb 2, 2016

Azure Show All Running Resources Free

@EgoAleSum Behind these two results are two different APIs. Get-AzureRmVM calls the VM Model View API which doesn't have the statuses, Get-AzureRmVm -Status calls the Instance View API which returns the statuses for each of the VM resources (VM, disks and extensions)

commented May 21, 2016

One limitation of this approach is getting a list of your VMs together with their current status (running or not).

It's a common scenario especially for people with many VMs. Unless I am missing something, they now need to do one API call for each VM which is time consuming especially compared to the single old ASM call Get-AzureVM FT Name, Status.

Please consider allowing GetAzureRmVM -Status without specifying the VM and RG if possible.

commented May 28, 2016

Ain't pretty, but you can do this: Get-AzureRmVM -ResourceGroupName [RG] get-azurermvm -Status ?{$_.statuses.displaystatus -eq 'VM running'} select name

commented May 31, 2016

@neaorin@ned1313 We could explore calling both APIs (model and instance view) and display the most important VM properties + VM status for a vanilla Get-AzureRmVm call (without any parameters). However, this will mean more time to return the result since more API calls need to be made esp. if you have a large number of VMs in your subscription. Will the performance hit be acceptable?

commented Jun 1, 2016

The performance hit might be fine for some users (myself included) and not acceptable for others. In my view, if the performance hit is significant then it would be better to have the user opt-in by explicitly requesting instance information - for instance GetAzureRmVM -Status.

Azure show all running resources for adults

commented Jun 1, 2016

I'd like to see it scoped to a VM or ResourceGroup, so if you want to use the -Status switch it either requires a VM name or ResourceGroup name.

commented Jun 28, 2016

Further more, the same command returns different objects depending on -Status switch

commented Sep 1, 2016
edited

Or you can do this way..

Get-AzureRmResource ?{$.ResourceType -eq 'Microsoft.Compute/virtualMachines'} foreach {get-azurermvm -ResourceGroupName $.ResourceGroupName -Name $.ResourceName
-Status ?{$
.Statuses[1].DisplayStatus -match 'VM Running'} select Name, ResourceGroupName, @{Label='VMStatus';Expression={'Running'}}}

commented Sep 23, 2016

I wish I could get the disk uris, as the instance view just display the names...
To delete the deallocated VMs' disks:
((Get-AzureRmVM -ResourceGroupName $ResourceGroupName) foreach-object{Get-AzureRmVM -Name $.Name -ResourceGroupName $ResourceGroupName -Status} where-Object {$.Statuses.Code -eq 'PowerState/deallocated' }) foreach-object{ Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $.name} %{ Remove-AzureStorageBlob -Blob $.StorageProfile.OsDisk.Vhd.Uri.Split('/')[-1] -Container $_.StorageProfile.OsDisk.Vhd.Uri.Split('/')[-2] -Force}
Looks horrible...

commented Sep 23, 2016
edited

@ShabuddinKhan You're missing a _ from '$_` in the command you pasted.

We explored spitting out statuses on our end but quickly realized there is a chance users might hit the API throttling limits because you need to make an instance view API call for each VM in your subscription. Say if you have 5000 VMs in your subscription and you run the Get-AzureRmVm 3 or more times within an hour, you are very likely to hit the throttling limits.

commented Oct 6, 2016

$ResourceGroupName='GSRG'
$Name='*'

Get-AzureRmVM -ResourceGroupName $ResourceGroupName
Get-AzureRmVM -Status
Select-Object -Property Name, Statuses
Where-Object {$.Name -like $Name}
ForEach-Object {
$VMName = $
.Name
$.Statuses
Where-Object {$
.Code -like 'PowerState/*'}
ForEach-Object {
New-Object -TypeName psobject -Property @{
Name = $VMName
Status = $_.DisplayStatus
}
}
}

commented Oct 6, 2016

Another one-liner I use frequently to show me Resource Group, VM Name, and current status:

commented Feb 10, 2017

I think this will accomplish the same thing as above:
Get-AzureRmVM -Status Select ResourceGroupName, Name, PowerState

commented Jul 7, 2017

@singhkays I do not understand why this issue was closed. At a minimum the powershell team could open a issue with the compute API team then track this once the ARM api is fixed.

commented Jul 7, 2017

@erichexter It was closed because the OPs question was resolved. However, since then PowerShell now allows you to do Get-AzureRmVM -Status to get status of all VMs in your sub. NOTE: Keep in mind that this is still calling the LIST API for ALL VMs + GET API for each VM so there could be a throttling if your sub has a lot of VMs.

commented Jul 9, 2018

@singhkays thankyou.. your response really helped me today :)

referenced this issue Jul 23, 2018

Open

Get-AzureRMVM -Status yields different result when running against a single machine rather than a pool of machines #3896

commented Jan 19, 2019

It is painful to duplicate Get-AzureRmVm two times. It would be good to have it in the vm object

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment