Last active
July 27, 2022 19:01
-
-
Save BlueDoge/c91060394c5882bb96fbaf56ada0a840 to your computer and use it in GitHub Desktop.
Another EC2 Instance Grabber that pairs InstanceIds with PrivateIpAddresses
This file contains 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
#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