powershell 有用的AWS PS命令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 有用的AWS PS命令相关的知识,希望对你有一定的参考价值。

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

以上是关于powershell 有用的AWS PS命令的主要内容,如果未能解决你的问题,请参考以下文章

如何在命令行执行 powershell 脚本

如何在命令行执行 powershell 脚本

如何在PowerShell中连续执行命令

powershell [PS:设置OWA邮箱策略]命令将特定OWA策略设置为用户#PowerShell#Office365

Powershell:如何在未连接的计算机上安装适用于 PowerShell 的 Nuget 提供程序,以便可以从 PS 命令行安装 nuget 包?

powershell 一些与AppFabric一起使用的有用命令