Azure PowerShell List Endpoints

1.7k Views Asked by At

We have an Azure account with a lot of VMs. I need a script that can list all powered on machines that has endpoints - and list the endpoints + ACL.

We're trying to track down servers with open SSH endpoints without having to do it manually. The script that I tried to work didn't work.

Get-AzureVM | where {$_.Status -ne "ReadyRole"} | Get-AzureEndpoint | select LocalPort, Port, Protocol, Vip, Acl, VirtualIPName

Thank you!

1

There are 1 best solutions below

0
On

you need to step through each VM's endpoint:

$ReadyVMs = Get-AzureVM | ? Status -eq ReadyRole
ForEach ($VM in $ReadyVMs) {
   $EndPoint = $VM | Get-AzureEndpoint
   If ($EndPoint.LocalPort -eq 22) { #or whatever port you need
      If (($EndPoint.Acl).Count -gt 0) {
         $EndPoint.Acl
      }
      Else {
         Write-Host "No ACL found for $($EndPoint.Name) on $($VM.Name)"
      }
   }
}