Skip to content

Instantly share code, notes, and snippets.

@BlueDoge
Last active July 27, 2022 19:01
Show Gist options
  • Save BlueDoge/c91060394c5882bb96fbaf56ada0a840 to your computer and use it in GitHub Desktop.
Save BlueDoge/c91060394c5882bb96fbaf56ada0a840 to your computer and use it in GitHub Desktop.
Another EC2 Instance Grabber that pairs InstanceIds with PrivateIpAddresses
#Created by Elizabeth Clements in 2022
#License MIT
$AWSRegion = 'us-west-2'
$AWSProfileLocation = ("$env:USERPROFILE\.aws\credentials")
$AWSProfileName = 'default'
# grab clipboard, let it parse it to an array if multilined
$ClipboardData = Get-Clipboard
if($ClipboardData.Length -gt 0) # Really there should be more validation than simply this.
{
$ListOfInstances = (Get-EC2Instance -Region $AWSRegion -ProfileLocation $AWSProfileLocation -ProfileName $AWSProfileName).Instances `
| Select-Object `
@{Name="ServerAlias"; Expression={$_.Tags | Where-Object Key -eq "Name" | Select-Object Value -ExpandProperty Value}} `
, @{Name="State"; Expression={$_.State.Name}} `
, InstanceId, PrivateIpAddress `
| Where-Object { $ClipboardData.Contains($_.InstanceId) }
$UserSelectedData = $ListOfInstances `
| Out-GridView -PassThru
if($UserSelectedData.Length -gt 0)
{
Set-Clipboard -Value $UserSelectedData
$Message = $UserSelectedData | Format-Table InstanceId, ServerAlias, State, PrivateIpAddress | Out-String
Write-Host $Message
}
else
{
Set-Clipboard -Value $ListOfInstances
$Message = $ListOfInstances | Format-Table InstanceId, ServerAlias, State, PrivateIpAddress | Out-String
Write-Host $Message
}
}
else
{
Write-Error -Message "Error! You need instance ids in your clipboard"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment