Skip to content

Instantly share code, notes, and snippets.

@pkirch
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pkirch/ab9c9ec3cd2314b47438 to your computer and use it in GitHub Desktop.
Save pkirch/ab9c9ec3cd2314b47438 to your computer and use it in GitHub Desktop.
This sample shows three ways to get the endpoints in an Azure subscription.
# sample 1
Get-AzureVM | Get-AzureEndpoint
# sample 2
Get-AzureVM | Get-AzureEndpoint | Select-Object -Property Vip, Name, Port, LocalPort | Format-Table -AutoSize
# sample 3
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
@pkirch
Copy link
Author

pkirch commented Jan 28, 2015

This sample script is used in the Microsoft Virtual Academy Course "PowerShell: Azure-Automatisierung für Einsteiger" at http://www.microsoftvirtualacademy.com/training-courses/powershell-azure-automatisierung-f-r-einsteiger-.

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