Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active February 18, 2019 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/b06a78f5c95ba78706c6fec5f13de9c9 to your computer and use it in GitHub Desktop.
Save techthoughts2/b06a78f5c95ba78706c6fec5f13de9c9 to your computer and use it in GitHub Desktop.
Install-Module AWSPowerShell.NetCore
Install-Module AWSLambdaPSCore
$accessKey = "YourAccessKey"
$secretKey = "YourSecretKey"
$awsc = New-AWSCredential -AccessKey $accessKey -SecretKey $secretKey
Get-AWSRegion
$region = "YourRegion"
Get-EC2Instance -Credential $awsc -Region $$region
$Instances = (Get-EC2Instance).instances
$VPCS = Get-EC2Vpc
foreach ($VPC in $VPCS) {
$Instances | Where-Object {$_.VpcId -eq $VPC.VpcId} | foreach {
New-Object -TypeName PSObject -Property @{
'VpcId' = $_.VpcId
'VPCName' = ($VPC.Tags | Where-Object {$_.Key -eq 'Name'}).Value
'InstanceId' = $_.InstanceId
'InstanceName' = ($_.Tags | Where-Object {$_.Key -eq 'Name'}).Value
'LaunchTime' = $_.LaunchTime
'State' = $_.State.Name
'KeyName' = $_.KeyName
}
}
}
#saving AWS keys as an AWS profile
Set-AWSCredential -AccessKey AKIAIOSFODNN7EXAMPLE -SecretKey wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY -StoreAs MyProfileName
#get latest windows AMI
#https://aws.amazon.com/blogs/compute/query-for-the-latest-amazon-linux-ami-ids-using-aws-systems-manager-parameter-store/
Get-EC2ImageByName -Name Windows_Server*2016* -Region us-west-2 | Sort-Object CreationDate | Select-Object Name
Get-SSMParameter -Name /aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Base -region us-west-2
Get-SSMParameter -Name /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
Get-SSMParametersByPath -Path "/aws/service/ami-amazon-linux-latest" -region us-west-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment