· 7 years ago · Sep 22, 2018, 05:26 AM
1Install-Module AWSPowerShell.NetCore
2Install-Module AWSLambdaPSCore
3$accessKey = "YourAccessKey"
4$secretKey = "YourSecretKey"
5$awsc = New-AWSCredential -AccessKey $accessKey -SecretKey $secretKey
6Get-AWSRegion
7$region = "YourRegion"
8Get-EC2Instance -Credential $awsc -Region $$region
9
10$Instances = (Get-EC2Instance).instances
11$VPCS = Get-EC2Vpc
12foreach ($VPC in $VPCS) {
13 $Instances | Where-Object {$_.VpcId -eq $VPC.VpcId} | foreach {
14 New-Object -TypeName PSObject -Property @{
15 'VpcId' = $_.VpcId
16 'VPCName' = ($VPC.Tags | Where-Object {$_.Key -eq 'Name'}).Value
17 'InstanceId' = $_.InstanceId
18 'InstanceName' = ($_.Tags | Where-Object {$_.Key -eq 'Name'}).Value
19 'LaunchTime' = $_.LaunchTime
20 'State' = $_.State.Name
21 'KeyName' = $_.KeyName
22 }
23 }
24}