Created
June 25, 2021 22:25
-
-
Save Rugby-Ball/0aee8d1c204e4d07494342fcd3f1f5d9 to your computer and use it in GitHub Desktop.
This will give Application Load Balancer details, list all Target Groups and Instances associated to them. #Utility #AWS #Inventory #AWS_ELB #AWS_ALB
This file contains hidden or 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
| #ALB-Detail.ps1 | |
| #This will give Application Load Balancer details, list all Target Groups and Instances associated to them. | |
| #It works, but I am adding some new features, like cross-region scanning, so consider this a work in progress for now. | |
| #Created Dtae; 6/25/2021 | |
| #Modified Date: 6/25/2021 | |
| #Created by: Ed Walsh | |
| $out = @() | |
| $o = "" | |
| $elb2s = Get-ELB2LoadBalancer | where Type -eq "application" | |
| foreach ($elb2 in $elb2s) { | |
| $elb2tgs = Get-ELB2TargetGroup -LoadBalancerArn $elb2.LoadBalancerArn | |
| $tg_count = ($elb2tgs | Measure-object).count | |
| foreach ($elb2tg in $elb2tgs) { | |
| $tg_ec2ids = (Get-ELB2TargetHealth -TargetGroupArn $elb2tg.TargetGroupArn).Target.ID | |
| If ( ($tg_ec2ids | Measure-Object).count -lt 1) { | |
| $o = New-Object -TypeName System.Management.Automation.PSObject -Property ([ordered]@{ | |
| 'VPC-ID' = $elb2tg.vpcid; | |
| 'ALB-Create-Time' = $elb2.createdtime ; | |
| 'ALB-Name' = $elb2.loadbalancername ; | |
| 'ALB-Scheme' = $elb2.Scheme ; | |
| 'ALB-Type' = $elb2.Type ; | |
| 'ALB-Security-Groups' = $elb2.SecurityGroups ; | |
| 'Target-Group-count' = $tg_count ; | |
| 'Target-Group-Name' = $elb2tg.TargetGroupName ; | |
| 'Target-Count' = ($tg_ec2ids | Measure-Object).count; | |
| 'EC2-ID' = ""; | |
| 'EC2-Name' = ""; | |
| }) | |
| $out += $o} | |
| Else { | |
| foreach ($tg_ec2id in $tg_ec2ids) { | |
| $ec2name = (Get-EC2Tag <# -Region $region #> -Filter @{Name="resource-type";Value="instance"},@{Name="resource-id";Value=$tg_ec2id},@{Name="key";Value="Name"} | Select-Object @{Name="Name";Expression={$PSItem.Value}} ).name | |
| $o = New-Object -TypeName System.Management.Automation.PSObject -Property ([ordered]@{ | |
| 'VPC-ID' = $elb2tg.vpcid; | |
| 'ALB-Create-Time' = $elb2.createdtime ; | |
| 'ALB-Name' = $elb2.loadbalancername ; | |
| 'ALB-Scheme' = $elb2.Scheme ; | |
| 'ALB-Type' = $elb2.Type ; | |
| 'ALB-Security-Groups' = $elb2.SecurityGroups ; | |
| 'Target-Group-count' = $tg_count ; | |
| 'Target-Group-Name' = $elb2tg.TargetGroupName ; | |
| 'Target-Count' = ($tg_ec2ids | Measure-Object).count; | |
| 'EC2-ID' = $tg_ec2id; | |
| 'EC2-Name' = $ec2name; | |
| }) | |
| $out += $o | |
| } | |
| } | |
| } | |
| } | |
| $out | Out-Gridview |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment