Skip to content

Instantly share code, notes, and snippets.

@pkirch
Created January 2, 2015 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkirch/3da0bec11b5ea037185e to your computer and use it in GitHub Desktop.
Save pkirch/3da0bec11b5ea037185e to your computer and use it in GitHub Desktop.
Get all endpoints in an Azure Subscription - third approach with formatted output and related cloud service and VM name.
# Get all Azure VMs in the current subscription.
Get-AzureVM | ForEach-Object {
# Save the current VM for use in the nested ForEach.
$vm = $_
# Get all endpoints of the current VM.
$endpoints = Get-AzureEndpoint -VM $vm
# Iterate all endpoints of the current VM.
$output = $endpoints | ForEach-Object {
# Create our own set of properties we want for output.
$hashtable = @{ServiceName=$vm.ServiceName; InstanceName=$vm.InstanceName; DNSName=$vm.DNSName; Protocol=$_.Name; Vip=$_.Vip; ExternalPort=$_.Port; InternalPort=$_.LocalPort}
# Create a new PowerShell object for output.
New-Object PSObject -Property $hashtable
}
$output
} | Format-Table -Property ServiceName, InstanceName, Vip, Protocol, ExternalPort, InternalPort, DNSName -AutoSize
<# Output
ServiceName InstanceName Vip Protocol ExternalPort InternalPort DNSName
----------- ------------ --- -------- ------------ ------------ -------
leasetest2 host2 104.40.188.19 PowerShell 5986 5986 http://leasetest2.cloudapp.net/
leasetest2 host2 104.40.188.19 Remote Desktop 56595 3389 http://leasetest2.cloudapp.net/
leasetest4 host4 191.233.81.126 PowerShell 5986 5986 http://leasetest4.cloudapp.net/
leasetest4 host4 191.233.81.126 Remote Desktop 61942 3389 http://leasetest4.cloudapp.net/
leasetest5 host5 137.117.194.91 PowerShell 5986 5986 http://leasetest5.cloudapp.net/
leasetest5 host5 137.117.194.91 Remote Desktop 63809 3389 http://leasetest5.cloudapp.net/
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment