Skip to content

Instantly share code, notes, and snippets.

@Rugby-Ball
Created January 15, 2022 00:11
Show Gist options
  • Select an option

  • Save Rugby-Ball/06d539eaab7000d882fe48998d80f33a to your computer and use it in GitHub Desktop.

Select an option

Save Rugby-Ball/06d539eaab7000d882fe48998d80f33a to your computer and use it in GitHub Desktop.
Scan Each Region, Each VPC, Each Subnet for Available ENI and count the IP's associated to the ENI. #Utility #AWS #Public #Inventory
#Check-for-available-AWS-ENI.ps1
<#
Scan Each Region, Each VPC, Each Subnet for Available ENI and count the IP's associated to the ENI. Use it to clean up un-used ENI and regain those Private IP's
#>
(Get-EC2Region).regionname | foreach { (Get-EC2Vpc -Region $_).vpcid | foreach { Get-EC2Subnet -Filter @{Name="vpc-id";Value="$_"} | foreach { Get-EC2NetworkInterface -Filter @(@{Name="subnet-id";Values=$_.subnetid} ; @{Name="status";Values="available"} ) | Select-Object VPCID, InterfaceType, NetworkInterfaceID, @{n="PrivateIP-Count"; e= {($_.privateipaddresses | Measure-Object).count}}, SubnetID, Status } } } | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment