2016-09-06 152 views

回答

3

首先,PowerShell的5.0或更高版本安装AWS的PowerShell模块:

Install-Module -Name AWSPowerShell -Scope CurrentUser -Force 

现在,到了IAM控制台,并生成一个快捷键,并使用以下命令来设置您的凭据在PowerShell中。

$AccessKey = '<YourAccessKey>' 
$SecretKey = '<SecretKey>' 
$Region = 'us-west-1' 
Initialize-AWSDefaults -AccessKey $AccessKey -SecretKey $SecretKey -Region $Region 

现在你从PowerShell的认证,使用下面的一行程序脚本弹出一个WPF窗口EC2实例中打开一个列表,然后选择要标记的人。

(Get-EC2Instance).Instances | 
    Out-GridView -OutputMode Multiple | 
    ForEach-Object -Process { 
    New-EC2Tag -Tag (New-Object -TypeName Amazon.EC2.Model.Tag -ArgumentList @('Key', 'Value')) -Resource $PSItem.InstanceId 
    } 
2

PS命令​​

New-EC2Tag -ResourceId $Instances -Tags $Tags 

从AWS文档....

$tag = New-Object Amazon.EC2.Model.Tag 
$tag.Key = "myTag" 
$tag.Value = "myTagValue" 

New-EC2Tag -Resource i-12345678 -Tag $tag