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