S.D.
S.D.

Reputation: 1201

AWS Powershell command to retrieve all secondary private IPs attached to EC2 instance

I was able to pull the PrivateIpAddress attached to the EC2 instance using below script but trying to find a way to get all the 'Secondary private IPs'

$fltr =  New-Object Amazon.EC2.Model.Filter
$fltr.Name = 'tag:Name'
$fltr.Values = 'server01'
$e=Get-EC2Instance -Filter $fltr
$e.Instances.PrivateIpAddress

Upvotes: 3

Views: 843

Answers (1)

S.D.
S.D.

Reputation: 1201

I have found a solution for this.

$fltr =  New-Object Amazon.EC2.Model.Filter
$fltr.Name = 'tag:Name'
$fltr.Values = 'server01'
$e=Get-EC2Instance -Filter $fltr
$e.Instances.PrivateIpAddress
(Get-EC2NetworkInterface -Filter @{Name='addresses.private-ip-address';values=$e.Instances.PrivateIpAddress} | 
select -ExpandProperty PrivateIpAddresses | 
where{$_.primary -ne $true}).PrivateIpAddress

Upvotes: 2

Related Questions