PowerShell code snippet below will get or display the Public and Private IP Address of all running instances that matches the Tag Key and Value specified.
#replace the access key, secret key and region with the actual value
$accesskey = 'acces-key'
$secretkey = 'secret-key'
$dregion = 'us-east-1'
#Display Public and Private IP Address of the Instance
(Get-EC2Instance -AccessKey $accesskey -SecretKey $secretkey -Region $dregion) | Select -ExpandProperty RunningInstance | ? {$_.Tag.Key -eq "Server" -and $_.Tag.Value -eq "Web-Server"} | Select-Object PrivateIpAddress, PublicIpAddress
#Replace the Tag Key and Tag Value as required
#$_.Tag.Key -eq "Server"
#$_.Tag.Value -eq "Web-Server"
Comments
Post a Comment