Created
January 2, 2015 15:23
-
-
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.
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
# 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
I use this Gist in my blog post on http://blogs.msdn.com/b/pkirchner/archive/2015/01/02/tipp-powershell-amp-azure-alle-offenen-ports-in-einer-subscription-auflisten.aspx.