Once you call Get-AzureEndpoint
you no longer have VM objects, you have Endpoint objects, which have different properties. You then filter out the endpoints you want, but now you are missing the properties of the VMs.
Possible solution: loop through all endpoints of each VM
$VMs = Get-AzureVM 'myservicename'
foreach ($VM in $VMs) {
# check if the current VM has an endpoint with port 80
$HttpEndpoint = Get-AzureEndpoint -VM $VM | where { $_.Port -eq 80 }
if ($HttpEndpoint) {
$VM.Name
}
}
This is assuming, the endpoints don't contain the name of the VM they belong to. Otherwise you could of course just do
... where { $_.Port -eq 80 } | select InstanceName # or whatever the name of the property with the VM name is
Followup:
To query additional ports:
where { $_.Port -eq 80 -or $_.Port -eq 443 }
or:
where { 80, 443 -contains $_.Port }
or with PowerShell 3 and later:
where { $_.Port -in 80, 443 }