Last active
May 16, 2017 14:46
-
-
Save pkirch/1ec6f3c1ca057b8beefb to your computer and use it in GitHub Desktop.
Group VMs by Cloud Services. Used as answer in Stack Overflow: http://stackoverflow.com/questions/34714061/how-to-list-all-cloud-service-in-azure-powershell-and-then-loop-each-cloud-servi/34725686#34725686
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$allVMs = Get-AzureVM | |
$allVMs | Group-Object -Property ServiceName | |
<# Output | |
Count Name Group | |
----- ---- ----- | |
2 pksttest1 {Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMRoleListContext, Microsoft.WindowsAzure.Commands.ServiceManage... | |
1 pksttest2 {Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMRoleListContext} | |
#> | |
$services = Get-AzureVM | Group-Object -Property ServiceName | |
foreach ($service in $services) { | |
# Output cloud service name | |
"Cloud Service '$($service.Name)'" | |
# Output VMs in that cloud service | |
foreach ($vm in $service.Group) { | |
"VM '$($vm.HostName)'" | |
} | |
} | |
<# Output | |
Cloud Service 'pksttest1' | |
VM 'host1' | |
VM 'host3' | |
Cloud Service 'pksttest2' | |
VM 'host2' | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment