Skip to content

Instantly share code, notes, and snippets.

@pkirch
Last active May 16, 2017 14:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkirch/1ec6f3c1ca057b8beefb to your computer and use it in GitHub Desktop.
Save pkirch/1ec6f3c1ca057b8beefb to your computer and use it in GitHub Desktop.
$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