

的版本 5 (V5) AWS Tools for PowerShell 已经发布！

有关重大更改和迁移应用程序的信息，请参阅[迁移主题](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用适用于 PowerShell V5 的工具的亚马逊 EC2 示例
<a name="powershell_ec2_code_examples"></a>

以下代码示例向您展示了如何使用带有 Amazon EC2 的 AWS Tools for PowerShell V5 来执行操作和实现常见场景。

*操作*是大型程序的代码摘录，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `Add-EC2CapacityReservation`
<a name="ec2_CreateCapacityReservation_powershell_topic"></a>

以下代码示例演示了如何使用 `Add-EC2CapacityReservation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用指定的属性创建新的容量预留。**  

```
Add-EC2CapacityReservation -InstanceType m4.xlarge -InstanceCount 2 -AvailabilityZone eu-west-1b -EbsOptimized True -InstancePlatform Windows
```
**输出**：  

```
AvailabilityZone       : eu-west-1b
AvailableInstanceCount : 2
CapacityReservationId  : cr-0c1f2345db6f7cdba
CreateDate             : 3/28/2019 9:29:41 AM
EbsOptimized           : True
EndDate                : 1/1/0001 12:00:00 AM
EndDateType            : unlimited
EphemeralStorage       : False
InstanceMatchCriteria  : open
InstancePlatform       : Windows
InstanceType           : m4.xlarge
State                  : active
Tags                   : {}
Tenancy                : default
TotalInstanceCount     : 2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateCapacityReservation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Add-EC2InternetGateway`
<a name="ec2_AttachInternetGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Add-EC2InternetGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的互联网网关连接到指定的 VPC。**  

```
Add-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d -VpcId vpc-12345678
```
**示例 2：此示例创建一个 VPC 和一个互联网网关，然后将互联网网关连接到 VPC。**  

```
$vpc = New-EC2Vpc -CidrBlock 10.0.0.0/16
New-EC2InternetGateway | Add-EC2InternetGateway -VpcId $vpc.VpcId
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AttachInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Add-EC2NetworkInterface`
<a name="ec2_AttachNetworkInterface_powershell_topic"></a>

以下代码示例演示了如何使用 `Add-EC2NetworkInterface`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的网络接口连接到指定的实例。**  

```
Add-EC2NetworkInterface -NetworkInterfaceId eni-12345678 -InstanceId i-1a2b3c4d -DeviceIndex 1
```
**输出**：  

```
eni-attach-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AttachNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Add-EC2Volume`
<a name="ec2_AttachVolume_powershell_topic"></a>

以下代码示例演示了如何使用 `Add-EC2Volume`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的卷连接到指定的实例，并使用指定的设备名称公开它。**  

```
Add-EC2Volume -VolumeId vol-12345678 -InstanceId i-1a2b3c4d -Device /dev/sdh
```
**输出**：  

```
AttachTime          : 12/22/2015 1:53:58 AM
DeleteOnTermination : False
Device              : /dev/sdh
InstanceId          : i-1a2b3c4d
State               : attaching
VolumeId            : vol-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AttachVolume](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Add-EC2VpnGateway`
<a name="ec2_AttachVpnGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Add-EC2VpnGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的虚拟专用网关连接到指定的 VPC。**  

```
Add-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678
```
**输出**：  

```
State        VpcId
-----        -----
attaching    vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AttachVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Approve-EC2VpcPeeringConnection`
<a name="ec2_AcceptVpcPeeringConnection_powershell_topic"></a>

以下代码示例演示了如何使用 `Approve-EC2VpcPeeringConnection`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例批准了请求的 VpcPeeringConnectionId pcx-1dfad234b56ff78be**  

```
Approve-EC2VpcPeeringConnection -VpcPeeringConnectionId pcx-1dfad234b56ff78be
```
**输出**：  

```
AccepterVpcInfo        : Amazon.EC2.Model.VpcPeeringConnectionVpcInfo
ExpirationTime         : 1/1/0001 12:00:00 AM
RequesterVpcInfo       : Amazon.EC2.Model.VpcPeeringConnectionVpcInfo
Status                 : Amazon.EC2.Model.VpcPeeringConnectionStateReason
Tags                   : {}
VpcPeeringConnectionId : pcx-1dfad234b56ff78be
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AcceptVpcPeeringConnection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Confirm-EC2ProductInstance`
<a name="ec2_ConfirmProductInstance_powershell_topic"></a>

以下代码示例演示了如何使用 `Confirm-EC2ProductInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例确定指定的产品代码是否与指定的实例相关联。**  

```
Confirm-EC2ProductInstance -ProductCode 774F4FF8 -InstanceId i-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ConfirmProductInstance](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Copy-EC2Image`
<a name="ec2_CopyImage_powershell_topic"></a>

以下代码示例演示了如何使用 `Copy-EC2Image`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将“欧洲地区（爱尔兰）”区域中的指定 AMI 复制到“美国西部（俄勒冈州）”区域。如果未指定 -Region，则使用当前默认区域作为目标区域。**  

```
Copy-EC2Image -SourceRegion eu-west-1 -SourceImageId ami-12345678 -Region us-west-2 -Name "Copy of ami-12345678"
```
**输出**：  

```
ami-87654321
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CopyImage](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Copy-EC2Snapshot`
<a name="ec2_CopySnapshot_powershell_topic"></a>

以下代码示例演示了如何使用 `Copy-EC2Snapshot`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的快照从欧洲地区（爱尔兰）区域复制到美国西部（俄勒冈州）区域。**  

```
Copy-EC2Snapshot -SourceRegion eu-west-1 -SourceSnapshotId snap-12345678 -Region us-west-2
```
**示例 2：如果您设置了默认区域并省略了 Region 参数，则默认目标区域为默认区域。**  

```
Set-DefaultAWSRegion us-west-2
Copy-EC2Snapshot -SourceRegion eu-west-1 -SourceSnapshotId snap-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CopySnapshot](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Deny-EC2VpcPeeringConnection`
<a name="ec2_RejectVpcPeeringConnection_powershell_topic"></a>

以下代码示例演示了如何使用 `Deny-EC2VpcPeeringConnection`。

**适用于 PowerShell V5 的工具**  
**示例 1：上面的示例拒绝了请求编号为 pcx-01a2b3ce45fe67eb8 的 VpcPeering 请求**  

```
Deny-EC2VpcPeeringConnection -VpcPeeringConnectionId pcx-01a2b3ce45fe67eb8
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RejectVpcPeeringConnection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Disable-EC2VgwRoutePropagation`
<a name="ec2_DisableVgwRoutePropagation_powershell_topic"></a>

以下代码示例演示了如何使用 `Disable-EC2VgwRoutePropagation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例禁止 VGW 自动将路由传播到指定的路由表。**  

```
Disable-EC2VgwRoutePropagation -RouteTableId rtb-12345678 -GatewayId vgw-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DisableVgwRoutePropagation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Disable-EC2VpcClassicLink`
<a name="ec2_DisableVpcClassicLink_powershell_topic"></a>

以下代码示例演示了如何使用 `Disable-EC2VpcClassicLink`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例禁用 vpc-01e23c4a5d6d EC2 VpcClassicLink b78e9。它返回 True 或 False**  

```
Disable-EC2VpcClassicLink -VpcId vpc-01e23c4a5d6db78e9
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DisableVpcClassicLink](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Disable-EC2VpcClassicLinkDnsSupport`
<a name="ec2_DisableVpcClassicLinkDnsSupport_powershell_topic"></a>

以下代码示例演示了如何使用 `Disable-EC2VpcClassicLinkDnsSupport`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例禁用了对 vpc-0b12d3456a7e ClassicLink 8910d 的 DNS 支持**  

```
Disable-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DisableVpcClassicLinkDnsSupport](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Dismount-EC2InternetGateway`
<a name="ec2_DetachInternetGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Dismount-EC2InternetGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的互联网网关与指定的 VPC 分离。**  

```
Dismount-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d -VpcId vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DetachInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Dismount-EC2NetworkInterface`
<a name="ec2_DetachNetworkInterface_powershell_topic"></a>

以下代码示例演示了如何使用 `Dismount-EC2NetworkInterface`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例移除网络接口和实例之间的指定连接。**  

```
Dismount-EC2NetworkInterface -AttachmentId eni-attach-1a2b3c4d -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DetachNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Dismount-EC2Volume`
<a name="ec2_DetachVolume_powershell_topic"></a>

以下代码示例演示了如何使用 `Dismount-EC2Volume`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例分离指定的卷。**  

```
Dismount-EC2Volume -VolumeId vol-12345678
```
**输出**：  

```
AttachTime          : 12/22/2015 1:53:58 AM
DeleteOnTermination : False
Device              : /dev/sdh
InstanceId          : i-1a2b3c4d
State               : detaching
VolumeId            : vol-12345678
```
**示例 2：您还可以指定实例 ID 和设备名称，以确保分离的卷正确无误。**  

```
Dismount-EC2Volume -VolumeId vol-12345678 -InstanceId i-1a2b3c4d -Device /dev/sdh
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DetachVolume](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Dismount-EC2VpnGateway`
<a name="ec2_DetachVpnGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Dismount-EC2VpnGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的虚拟专用网关与指定的 VPC 分离。**  

```
Dismount-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DetachVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2CapacityReservation`
<a name="ec2_ModifyCapacityReservation_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2CapacityReservation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例通过将实例计数更改为 1 来修改 CapacityReservationId cr-0c1f2345db6f7cdba**  

```
Edit-EC2CapacityReservation -CapacityReservationId cr-0c1f2345db6f7cdba -InstanceCount 1
```
**输出**：  

```
True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyCapacityReservation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2Host`
<a name="ec2_ModifyHosts_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2Host`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将专用主机的 AutoPlacement 设置修改为关闭 h-01e23f4cd567890f3**  

```
Edit-EC2Host -HostId h-03e09f8cd681609f3 -AutoPlacement off
```
**输出**：  

```
Successful            Unsuccessful
----------            ------------
{h-01e23f4cd567890f3} {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyHosts](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2IdFormat`
<a name="ec2_ModifyIdFormat_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2IdFormat`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的资源类型启用较长的 ID 格式。**  

```
Edit-EC2IdFormat -Resource instance -UseLongId $true
```
**示例 2：此示例为指定的资源类型禁用较长的 ID 格式。**  

```
Edit-EC2IdFormat -Resource instance -UseLongId $false
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2ImageAttribute`
<a name="ec2_ModifyImageAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2ImageAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例更新指定 AMI 的描述。**  

```
Edit-EC2ImageAttribute -ImageId ami-12345678 -Description "New description"
```
**示例 2：此示例将 AMI 设为公开（例如，任何人 AWS 账户 都可以使用）。**  

```
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup all
```
**示例 3：此示例将 AMI 设为私有（例如，只有作为所有者的您才能使用它）。**  

```
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserGroup all
```
**示例 4：此示例向指定的授予启动权限 AWS 账户。**  

```
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333
```
**示例 5：此示例从指定的中删除启动权限 AWS 账户。**  

```
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2InstanceAttribute`
<a name="ec2_ModifyInstanceAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2InstanceAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例修改指定实例的实例类型。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -InstanceType m3.medium
```
**示例 2：此示例通过将 “simple” 指定为单根虚拟化 (SR-IOV) 网络支持参数的值，为指定实例启用增强联网，方法是将 “simple” 指定为单根 I/O 虚拟化 (SR-IOV) 网络支持参数的值，-.. SriovNetSupport**   

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -SriovNetSupport "simple"
```
**示例 3：此示例修改指定实例的安全组。该实例必须在 VPC 中。您必须指定每个安全组的 ID，而不是名称。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -Group @( "sg-12345678", "sg-45678901" )
```
**示例 4：此示例为指定实例启用 EBS I/O 优化。此功能并非适用于所有实例类型。使用 EBS 优化的实例时，可能需要支付额外的使用费。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -EbsOptimized $true
```
**示例 5：此示例启用了对指定实例的 source/destination 检查。对于要执行 NAT 的 NAT 实例，该值必须为“false”。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -SourceDestCheck $true
```
**示例 6：此示例对指定的实例禁用终止。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -DisableApiTermination $true
```
**示例 7：此示例更改指定的实例，使其在从实例启动关闭时终止。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -InstanceInitiatedShutdownBehavior terminate
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyInstanceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2InstanceCreditSpecification`
<a name="ec2_ModifyInstanceCreditSpecification_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2InstanceCreditSpecification`。

**适用于 PowerShell V5 的工具**  
**示例 1：这会为实例 i-01234567890abcdef 启用 T2 无限积分。**  

```
$Credit = New-Object -TypeName Amazon.EC2.Model.InstanceCreditSpecificationRequest
$Credit.InstanceId = "i-01234567890abcdef"
$Credit.CpuCredits = "unlimited"
Edit-EC2InstanceCreditSpecification -InstanceCreditSpecification $Credit
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyInstanceCreditSpecification](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2NetworkInterfaceAttribute`
<a name="ec2_ModifyNetworkInterfaceAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2NetworkInterfaceAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例修改指定的网络接口，以便在终止时删除指定的连接。**  

```
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -Attachment_AttachmentId eni-attach-1a2b3c4d -Attachment_DeleteOnTermination $true
```
**示例 2：此示例修改指定网络接口的描述。**  

```
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -Description "my description"
```
**示例 3：此示例修改指定网络接口的安全组。**  

```
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -Groups sg-1a2b3c4d
```
**示例 4：此示例禁用对指定网络接口的 source/destination 检查。**  

```
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -SourceDestCheck $false
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyNetworkInterfaceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2ReservedInstance`
<a name="ec2_ModifyReservedInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2ReservedInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例修改指定预留实例的可用区、实例计数和平台。**  

```
$config = New-Object Amazon.EC2.Model.ReservedInstancesConfiguration
$config.AvailabilityZone = "us-west-2a"
$config.InstanceCount = 1
$config.Platform = "EC2-VPC"

Edit-EC2ReservedInstance `
-ReservedInstancesId @("FE32132D-70D5-4795-B400-AE435EXAMPLE", "0CC556F3-7AB8-4C00-B0E5-98666EXAMPLE") `
-TargetConfiguration $config
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyReservedInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2SnapshotAttribute`
<a name="ec2_ModifySnapshotAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2SnapshotAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例通过设置指定快照的 CreateVolumePermission 属性将其公开。**  

```
Edit-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute CreateVolumePermission -OperationType Add -GroupName all
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifySnapshotAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2SpotFleetRequest`
<a name="ec2_ModifySpotFleetRequest_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2SpotFleetRequest`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例更新指定竞价型实例集请求的目标容量。**  

```
Edit-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TargetCapacity 10
```
**输出**：  

```
True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifySpotFleetRequest](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2SubnetAttribute`
<a name="ec2_ModifySubnetAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2SubnetAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的子网启用公有 IP 寻址。**  

```
Edit-EC2SubnetAttribute -SubnetId subnet-1a2b3c4d -MapPublicIpOnLaunch $true
```
**示例 2：此示例为指定的子网禁用公有 IP 寻址。**  

```
Edit-EC2SubnetAttribute -SubnetId subnet-1a2b3c4d -MapPublicIpOnLaunch $false
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifySubnetAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2VolumeAttribute`
<a name="ec2_ModifyVolumeAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2VolumeAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例修改了指定卷的指定属性。 I/O 由于数据可能不一致，该卷的操作将在暂停后自动恢复。**  

```
Edit-EC2VolumeAttribute -VolumeId vol-12345678 -AutoEnableIO $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyVolumeAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Edit-EC2VpcAttribute`
<a name="ec2_ModifyVpcAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Edit-EC2VpcAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启用对指定 VPC 的 DNS 主机名的支持。**  

```
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsHostnames $true
```
**示例 2：此示例禁用对指定 VPC 的 DNS 主机名的支持。**  

```
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsHostnames $false
```
**示例 3：此示例启用对指定 VPC 的 DNS 解析的支持。**  

```
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsSupport $true
```
**示例 4：此示例禁用对指定 VPC 的 DNS 解析的支持。**  

```
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsSupport $false
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ModifyVpcAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Enable-EC2VgwRoutePropagation`
<a name="ec2_EnableVgwRoutePropagation_powershell_topic"></a>

以下代码示例演示了如何使用 `Enable-EC2VgwRoutePropagation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例支持指定的 VGW 自动将路由传播到指定的路由表。**  

```
Enable-EC2VgwRoutePropagation -RouteTableId rtb-12345678 -GatewayId vgw-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [EnableVgwRoutePropagation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Enable-EC2VolumeIO`
<a name="ec2_EnableVolumeIo_powershell_topic"></a>

以下代码示例演示了如何使用 `Enable-EC2VolumeIO`。

**适用于 PowerShell V5 的工具**  
**示例 1：如果禁用了 I/O 操作，则此示例将启用对指定卷的 I/O 操作。**  

```
Enable-EC2VolumeIO -VolumeId vol-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [EnableVolumeIo](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Enable-EC2VpcClassicLink`
<a name="ec2_EnableVpcClassicLink_powershell_topic"></a>

以下代码示例演示了如何使用 `Enable-EC2VpcClassicLink`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启用 VPC vpc-0123456b789b0d12f ClassicLink**  

```
Enable-EC2VpcClassicLink -VpcId vpc-0123456b789b0d12f
```
**输出**：  

```
True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [EnableVpcClassicLink](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Enable-EC2VpcClassicLinkDnsSupport`
<a name="ec2_EnableVpcClassicLinkDnsSupport_powershell_topic"></a>

以下代码示例演示了如何使用 `Enable-EC2VpcClassicLinkDnsSupport`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启用 vpc-0b12d3456a7e8910d 支持 DNS 主机名解析 ClassicLink**  

```
Enable-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d -Region eu-west-1
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [EnableVpcClassicLinkDnsSupport](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2AccountAttribute`
<a name="ec2_DescribeAccountAttributes_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2AccountAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了您是可以在该区域的 EC2-Classic 和 EC2-VPC 中启动实例，还是只能启动到-VPC 中 EC2。**  

```
(Get-EC2AccountAttribute -AttributeName supported-platforms).AttributeValues
```
**输出**：  

```
AttributeValue
--------------
EC2
VPC
```
**示例 2：此示例描述您的默认 VPC，或者如果您在该区域没有默认 VPC，则为“无”。**  

```
(Get-EC2AccountAttribute -AttributeName default-vpc).AttributeValues
```
**输出**：  

```
AttributeValue
--------------
vpc-12345678
```
**示例 3：此示例描述您可以运行的最大按需型实例数。**  

```
(Get-EC2AccountAttribute -AttributeName max-instances).AttributeValues
```
**输出**：  

```
AttributeValue
--------------
20
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAccountAttributes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Address`
<a name="ec2_DescribeAddresses_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Address`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了 EC2-Classic 中实例的指定弹性 IP 地址。**  

```
Get-EC2Address -AllocationId eipalloc-12345678
```
**输出**：  

```
AllocationId            : eipalloc-12345678
AssociationId           : eipassoc-12345678
Domain                  : vpc
InstanceId              : i-87654321
NetworkInterfaceId      : eni-12345678
NetworkInterfaceOwnerId : 12345678
PrivateIpAddress        : 10.0.2.172
PublicIp                : 198.51.100.2
```
**示例 2：此示例描述 VPC 中实例的弹性 IP 地址。此语法需要 PowerShell 版本 3 或更高版本。**  

```
Get-EC2Address -Filter @{ Name="domain";Values="vpc" }
```
**示例 3：此示例描述了 EC2-Classic 中实例的指定弹性 IP 地址。**  

```
Get-EC2Address -PublicIp 203.0.113.17
```
**输出**：  

```
AllocationId            :
AssociationId           :
Domain                  : standard
InstanceId              : i-12345678
NetworkInterfaceId      :
NetworkInterfaceOwnerId :
PrivateIpAddress        :
PublicIp                : 203.0.113.17
```
**示例 4：此示例描述了 EC2-Classic 中实例的弹性 IP 地址。此语法需要 PowerShell 版本 3 或更高版本。**  

```
Get-EC2Address -Filter @{ Name="domain";Values="standard" }
```
**示例 5：此示例描述所有弹性 IP 地址。**  

```
Get-EC2Address
```
**示例 6：此示例返回筛选条件中提供的实例 ID 的公有和私有 IP**  

```
Get-EC2Address -Region eu-west-1 -Filter @{Name="instance-id";Values="i-0c12d3f4f567ffb89"} | Select-Object PrivateIpAddress, PublicIp
```
**输出**：  

```
PrivateIpAddress PublicIp
---------------- --------
10.0.0.99        63.36.5.227
```
**示例 7：此示例检索所有 Elast IPs ic 及其分配 ID、关联 ID 和实例 ID**  

```
Get-EC2Address -Region eu-west-1 | Select-Object InstanceId, AssociationId, AllocationId, PublicIp
```
**输出**：  

```
InstanceId          AssociationId              AllocationId               PublicIp
----------          -------------              ------------               --------
                                               eipalloc-012e3b456789e1fad 17.212.120.178
i-0c123dfd3415bac67 eipassoc-0e123456bb7890bdb eipalloc-01cd23ebf45f7890c 17.212.124.77
                                               eipalloc-012345678eeabcfad 17.212.225.7
i-0123d405c67e89a0c eipassoc-0c123b456783966ba eipalloc-0123cdd456a8f7892 37.216.52.173
i-0f1bf2f34c5678d09 eipassoc-0e12934568a952d96 eipalloc-0e1c23e4d5e6789e4 37.218.222.278
i-012e3cb4df567e8aa eipassoc-0d1b2fa4d67d03810 eipalloc-0123f456f78a01b58 37.210.82.27
i-0123bcf4b567890e1 eipassoc-01d2345f678903fb1 eipalloc-0e1db23cfef5c45c7 37.215.222.270
```
**示例 8：此示例获取与标签键 “类别” 匹配且值为 “Prod” 的 EC2 IP 地址列表**  

```
Get-EC2Address -Filter @{Name="tag:Category";Values="Prod"}
```
**输出**：  

```
AllocationId            : eipalloc-0123f456f81a01b58
AssociationId           : eipassoc-0d1b23a456d103810
CustomerOwnedIp         :
CustomerOwnedIpv4Pool   :
Domain                  : vpc
InstanceId              : i-012e3cb4df567e1aa
NetworkBorderGroup      : eu-west-1
NetworkInterfaceId      : eni-0123f41d5a60d5f40
NetworkInterfaceOwnerId : 123456789012
PrivateIpAddress        : 192.168.1.84
PublicIp                : 34.250.81.29
PublicIpv4Pool          : amazon
Tags                    : {Category, Name}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAddresses](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2AvailabilityZone`
<a name="ec2_DescribeAvailabilityZones_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2AvailabilityZone`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述当前区域可供您使用的可用区。**  

```
Get-EC2AvailabilityZone
```
**输出**：  

```
Messages    RegionName    State        ZoneName
--------    ----------    -----        --------
{}          us-west-2     available    us-west-2a
{}          us-west-2     available    us-west-2b
{}          us-west-2     available    us-west-2c
```
**示例 2：此示例描述所有处于受损状态的可用区。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
Get-EC2AvailabilityZone -Filter @{ Name="state";Values="impaired" }
```
**示例 3：在 PowerShell 版本 2 中，必须使用 New-Object 来创建过滤器。**  

```
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = "state"
$filter.Values = "impaired"

Get-EC2AvailabilityZone -Filter $filter
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAvailabilityZones](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2BundleTask`
<a name="ec2_DescribeBundleTasks_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2BundleTask`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的捆绑包任务。**  

```
Get-EC2BundleTask -BundleId bun-12345678
```
**示例 2：此示例描述状态为“完成”或“失败”的捆绑包任务。**  

```
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = "state"
$filter.Values = @( "complete", "failed" )

Get-EC2BundleTask -Filter $filter
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeBundleTasks](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2CapacityReservation`
<a name="ec2_DescribeCapacityReservations_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2CapacityReservation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述该区域的一个或多个容量预留**  

```
Get-EC2CapacityReservation -Region eu-west-1
```
**输出**：  

```
AvailabilityZone       : eu-west-1b
AvailableInstanceCount : 2
CapacityReservationId  : cr-0c1f2345db6f7cdba
CreateDate             : 3/28/2019 9:29:41 AM
EbsOptimized           : True
EndDate                : 1/1/0001 12:00:00 AM
EndDateType            : unlimited
EphemeralStorage       : False
InstanceMatchCriteria  : open
InstancePlatform       : Windows
InstanceType           : m4.xlarge
State                  : active
Tags                   : {}
Tenancy                : default
TotalInstanceCount     : 2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeCapacityReservations](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2ConsoleOutput`
<a name="ec2_GetConsoleOutput_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2ConsoleOutput`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取指定 Linux 实例的控制台输出。控制台输出经过编码。**  

```
Get-EC2ConsoleOutput -InstanceId i-0e19abcd47c123456
```
**输出**：  

```
InstanceId          Output
----------          ------
i-0e194d3c47c123637 WyAgICAwLjAwMDAwMF0gQ29tbW...bGU9dHR5UzAgc2Vs
```
**示例 2：此示例将经过编码的控制台输出存储在变量中，然后对其进行解码。**  

```
$Output_encoded = (Get-EC2ConsoleOutput -InstanceId i-0e19abcd47c123456).Output
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Output_encoded))
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetConsoleOutput](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2CustomerGateway`
<a name="ec2_DescribeCustomerGateways_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2CustomerGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的客户网关。**  

```
Get-EC2CustomerGateway -CustomerGatewayId cgw-1a2b3c4d
```
**输出**：  

```
BgpAsn            : 65534
CustomerGatewayId : cgw-1a2b3c4d
IpAddress         : 203.0.113.12
State             : available
Tags              : {}
Type              : ipsec.1
```
**示例 2：此示例描述状态为待定或可用的所有客户网关。**  

```
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = "state"
$filter.Values = @( "pending", "available" )

Get-EC2CustomerGateway -Filter $filter
```
**示例 3：此示例描述所有客户网关。**  

```
Get-EC2CustomerGateway
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeCustomerGateways](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2DhcpOption`
<a name="ec2_DescribeDhcpOptions_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2DhcpOption`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例列出 DHCP 选项集。**  

```
Get-EC2DhcpOption
```
**输出**：  

```
DhcpConfigurations                    DhcpOptionsId    Tag
------------------                    -------------    ---
{domain-name, domain-name-servers}    dopt-1a2b3c4d    {}
{domain-name, domain-name-servers}    dopt-2a3b4c5d    {}
{domain-name-servers}                 dopt-3a4b5c6d    {}
```
**示例 2：此示例获取指定 DHCP 选项集的配置详细信息。**  

```
(Get-EC2DhcpOption -DhcpOptionsId dopt-1a2b3c4d).DhcpConfigurations
```
**输出**：  

```
Key                    Values
---                    ------
domain-name            {abc.local}
domain-name-servers    {10.0.0.101, 10.0.0.102}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2FlowLog`
<a name="ec2_DescribeFlowLogs_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2FlowLog`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述日志目标类型为“s3”的一个或多个流日志**  

```
Get-EC2FlowLog -Filter @{Name="log-destination-type";Values="s3"}
```
**输出**：  

```
CreationTime             : 2/25/2019 9:07:36 PM
DeliverLogsErrorMessage  :
DeliverLogsPermissionArn :
DeliverLogsStatus        : SUCCESS
FlowLogId                : fl-01b2e3d45f67f8901
FlowLogStatus            : ACTIVE
LogDestination           : arn:aws:s3:::amzn-s3-demo-bucket-dd-tata
LogDestinationType       : s3
LogGroupName             :
ResourceId               : eni-01d2dda3456b7e890
TrafficType              : ALL
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeFlowLogs](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Host`
<a name="ec2_DescribeHosts_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Host`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例返回 EC2 主机详细信息**  

```
Get-EC2Host
```
**输出**：  

```
AllocationTime    : 3/23/2019 4:55:22 PM
AutoPlacement     : off
AvailabilityZone  : eu-west-1b
AvailableCapacity : Amazon.EC2.Model.AvailableCapacity
ClientToken       :
HostId            : h-01e23f4cd567890f1
HostProperties    : Amazon.EC2.Model.HostProperties
HostReservationId :
Instances         : {}
ReleaseTime       : 1/1/0001 12:00:00 AM
State             : available
Tags              : {}
```
**示例 2：此示例查询主机 h-01e23f4c AvailableInstanceCapacity d567899f1**  

```
Get-EC2Host -HostId h-01e23f4cd567899f1 | Select-Object -ExpandProperty AvailableCapacity | Select-Object -expand AvailableInstanceCapacity
```
**输出**：  

```
AvailableCapacity InstanceType TotalCapacity
----------------- ------------ -------------
11                m4.xlarge    11
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeHosts](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2HostReservationOffering`
<a name="ec2_DescribeHostReservationOfferings_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2HostReservationOffering`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了可为给定过滤器 “实例系列” 购买的专用主机预留 PaymentOption ，其中 “” NoUpfront**  

```
Get-EC2HostReservationOffering -Filter @{Name="instance-family";Values="m4"} | Where-Object PaymentOption -eq NoUpfront
```
**输出**：  

```
CurrencyCode   :
Duration       : 94608000
HourlyPrice    : 1.307
InstanceFamily : m4
OfferingId     : hro-0c1f234567890d9ab
PaymentOption  : NoUpfront
UpfrontPrice   : 0.000

CurrencyCode   :
Duration       : 31536000
HourlyPrice    : 1.830
InstanceFamily : m4
OfferingId     : hro-04ad12aaaf34b5a67
PaymentOption  : NoUpfront
UpfrontPrice   : 0.000
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeHostReservationOfferings](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2HostReservationPurchasePreview`
<a name="ec2_GetHostReservationPurchasePreview_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2HostReservationPurchasePreview`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例预览配置与专属主机 h-01e23f4cd567890f1 的配置匹配的预留购买。**  

```
Get-EC2HostReservationPurchasePreview -OfferingId hro-0c1f23456789d0ab -HostIdSet h-01e23f4cd567890f1
```
**输出**：  

```
CurrencyCode Purchase TotalHourlyPrice TotalUpfrontPrice
------------ -------- ---------------- -----------------
             {}       1.307            0.000
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetHostReservationPurchasePreview](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2IdFormat`
<a name="ec2_DescribeIdFormat_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2IdFormat`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定资源类型的 ID 格式。**  

```
Get-EC2IdFormat -Resource instance
```
**输出**：  

```
Resource       UseLongIds
--------       ----------
instance       False
```
**示例 2：此示例描述了所有支持更长时间的资源类型的 ID 格式 IDs。**  

```
Get-EC2IdFormat
```
**输出**：  

```
Resource       UseLongIds
--------       ----------
reservation    False
instance       False
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2IdentityIdFormat`
<a name="ec2_DescribeIdentityIdFormat_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2IdentityIdFormat`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例返回给定角色的资源“image”的 ID 格式**  

```
Get-EC2IdentityIdFormat -PrincipalArn arn:aws:iam::123456789511:role/JDBC -Resource image
```
**输出**：  

```
Deadline             Resource UseLongIds
--------             -------- ----------
8/2/2018 11:30:00 PM image    True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeIdentityIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Image`
<a name="ec2_DescribeImages_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Image`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的 AMI。**  

```
Get-EC2Image -ImageId ami-12345678
```
**输出**：  

```
Architecture        : x86_64
BlockDeviceMappings : {/dev/xvda}
CreationDate        : 2014-10-20T00:56:28.000Z
Description         : My image
Hypervisor          : xen
ImageId             : ami-12345678
ImageLocation       : 123456789012/my-image
ImageOwnerAlias     :
ImageType           : machine
KernelId            :
Name                : my-image
OwnerId             : 123456789012
Platform            :
ProductCodes        : {}
Public              : False
RamdiskId           :
RootDeviceName      : /dev/xvda
RootDeviceType      : ebs
SriovNetSupport     : simple
State               : available
StateReason         :
Tags                : {Name}
VirtualizationType  : hvm
```
**示例 2：此示例描述 AMIs 了您拥有的。**  

```
Get-EC2Image -owner self
```
**示例 3：此示例描述了运行微软 Windows Server 的公众 AMIs 。**  

```
Get-EC2Image -Filter @{ Name="platform"; Values="windows" }
```
**示例 4：此示例描述了 “us-west-2” 区域的所有公众 AMIs 。**  

```
Get-EC2Image -Region us-west-2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeImages](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2ImageAttribute`
<a name="ec2_DescribeImageAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2ImageAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取指定 AMI 的描述。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute description
```
**输出**：  

```
BlockDeviceMappings : {}
Description         : My image description
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     :
```
**示例 2：此示例描述指定 AMI 的启动权限。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission
```
**输出**：  

```
BlockDeviceMappings : {}
Description         :
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {all}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     :
```
**示例 3：此示例测试是否启用增强联网。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute sriovNetSupport
```
**输出**：  

```
BlockDeviceMappings : {}
Description         :
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     : simple
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2ImportImageTask`
<a name="ec2_DescribeImportImageTasks_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2ImportImageTask`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的映像导入任务。**  

```
Get-EC2ImportImageTask -ImportTaskId import-ami-hgfedcba
```
**输出**：  

```
Architecture    : x86_64
Description     : Windows Image 2
Hypervisor      :
ImageId         : ami-1a2b3c4d
ImportTaskId    : import-ami-hgfedcba
LicenseType     : AWS
Platform        : Windows
Progress        :
SnapshotDetails : {/dev/sda1}
Status          : completed
StatusMessage   :
```
**示例 2：此示例描述所有映像导入任务。**  

```
Get-EC2ImportImageTask
```
**输出**：  

```
Architecture    :
Description     : Windows Image 1
Hypervisor      :
ImageId         :
ImportTaskId    : import-ami-abcdefgh
LicenseType     : AWS
Platform        : Windows
Progress        :
SnapshotDetails : {}
Status          : deleted
StatusMessage   : User initiated task cancelation

Architecture    : x86_64
Description     : Windows Image 2
Hypervisor      :
ImageId         : ami-1a2b3c4d
ImportTaskId    : import-ami-hgfedcba
LicenseType     : AWS
Platform        : Windows
Progress        :
SnapshotDetails : {/dev/sda1}
Status          : completed
StatusMessage   :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeImportImageTasks](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2ImportSnapshotTask`
<a name="ec2_DescribeImportSnapshotTasks_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2ImportSnapshotTask`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的快照导入任务。**  

```
Get-EC2ImportSnapshotTask -ImportTaskId import-snap-abcdefgh
```
**输出**：  

```
Description             ImportTaskId               SnapshotTaskDetail                                                          
-----------------       --------------------       ------------------                                                          
Disk Image Import 1     import-snap-abcdefgh       Amazon.EC2.Model.SnapshotTaskDetail
```
**示例 2：此示例描述所有快照导入任务。**  

```
Get-EC2ImportSnapshotTask
```
**输出**：  

```
Description             ImportTaskId               SnapshotTaskDetail                                                          
-----------------       --------------------       ------------------                                                          
Disk Image Import 1     import-snap-abcdefgh       Amazon.EC2.Model.SnapshotTaskDetail 
Disk Image Import 2     import-snap-hgfedcba       Amazon.EC2.Model.SnapshotTaskDetail
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeImportSnapshotTasks](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Instance`
<a name="ec2_DescribeInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Instance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的实例。**  

```
(Get-EC2Instance -InstanceId i-12345678).Instances
```
**输出**：  

```
AmiLaunchIndex        : 0
Architecture          : x86_64
BlockDeviceMappings   : {/dev/sda1}
ClientToken           : TleEy1448154045270
EbsOptimized          : False
Hypervisor            : xen
IamInstanceProfile    : Amazon.EC2.Model.IamInstanceProfile
ImageId               : ami-12345678
InstanceId            : i-12345678
InstanceLifecycle     :
InstanceType          : t2.micro
KernelId              :
KeyName               : my-key-pair
LaunchTime            : 12/4/2015 4:44:40 PM
Monitoring            : Amazon.EC2.Model.Monitoring
NetworkInterfaces     : {ip-10-0-2-172.us-west-2.compute.internal}
Placement             : Amazon.EC2.Model.Placement
Platform              : Windows
PrivateDnsName        : ip-10-0-2-172.us-west-2.compute.internal
PrivateIpAddress      : 10.0.2.172
ProductCodes          : {}
PublicDnsName         : 
PublicIpAddress       : 
RamdiskId             :
RootDeviceName        : /dev/sda1
RootDeviceType        : ebs
SecurityGroups        : {default}
SourceDestCheck       : True
SpotInstanceRequestId :
SriovNetSupport       :
State                 : Amazon.EC2.Model.InstanceState
StateReason           :
StateTransitionReason :
SubnetId              : subnet-12345678
Tags                  : {Name}
VirtualizationType    : hvm
VpcId                 : vpc-12345678
```
**示例 2：此示例描述您在当前区域中的所有实例，按预留分组。要查看实例详细信息，请在每个预留对象中展开实例集合。**  

```
Get-EC2Instance
```
**输出**：  

```
GroupNames    : {}
Groups        : {}
Instances     : {}
OwnerId       : 123456789012
RequesterId   : 226008221399
ReservationId : r-c5df370c

GroupNames    : {}
Groups        : {}
Instances     : {}
OwnerId       : 123456789012
RequesterId   : 854251627541
ReservationId : r-63e65bab
...
```
**示例 3：此示例说明如何使用筛选器查询 VPC 的特定子网中的 EC2 实例。**  

```
(Get-EC2Instance -Filter @{Name="vpc-id";Values="vpc-1a2bc34d"},@{Name="subnet-id";Values="subnet-1a2b3c4d"}).Instances
```
**输出**：  

```
InstanceId          InstanceType Platform PrivateIpAddress PublicIpAddress SecurityGroups SubnetId        VpcId
----------          ------------ -------- ---------------- --------------- -------------- --------        -----
i-01af...82cf180e19 t2.medium    Windows  10.0.0.98                        ...            subnet-1a2b3c4d vpc-1a2b3c4d
i-0374...7e9d5b0c45 t2.xlarge    Windows  10.0.0.53                        ...            subnet-1a2b3c4d vpc-1a2b3c4d
```
**示例 4：此示例说明如何使用具有多个值的筛选器来查询同时处于运行状态和已停止状态的 EC2 实例**  

```
$InstanceParams = @{
    Filter = @(
        @{'Name' = 'instance-state-name';'Values' = @("running","stopped")}
    )
}

(Get-EC2Instance @InstanceParams).Instances
```
**输出**：  

```
InstanceId          InstanceType Platform PrivateIpAddress PublicIpAddress SecurityGroups SubnetId        VpcId
----------          ------------ -------- ---------------- --------------- -------------- --------        -----
i-05a9...f6c5f46e18 t3.medium             10.0.1.7                         ...            subnet-1a2b3c4d vpc-1a2b3c4d
i-02cf...945c4fdd07 t3.medium    Windows  10.0.1.8                         ...            subnet-1a2b3c4d vpc-1a2b3c4d
i-0ac0...c037f9f3a1 t3.xlarge    Windows  10.0.1.10                        ...            subnet-1a2b3c4d vpc-1a2b3c4d
i-066b...57b7b08888 t3.medium    Windows  10.0.1.11                        ...            subnet-1a2b3c4d vpc-1a2b3c4d
i-0fee...82e83ccd72 t3.medium    Windows  10.0.1.5                         ...            subnet-1a2b3c4d vpc-1a2b3c4d
i-0a68...274cc5043b t3.medium    Windows  10.0.1.6                         ...            subnet-1a2b3c4d vpc-1a2b3c4d
```
**示例 5：此示例说明如何使用具有多个值的过滤器来查询同时运行和已停止的 EC2 实例，以及使用 Select-Object cmdlet 来选择要输出的特定值。**  

```
$InstanceParams = @{
    Filter = @(
        @{'Name' = 'instance-state-name';'Values' = @("running","stopped")}
    )
}

$SelectParams = @{
    Property = @(
        "InstanceID", "InstanceType", "Platform", "PrivateIpAddress",
        @{Name="Name";Expression={$_.Tags[$_.Tags.Key.IndexOf("Name")].Value}},
        @{Name="State";Expression={$_.State.Name}}
    )
}

$result = Get-EC2Instance @InstanceParams
$result.Instances | Select-Object @SelectParams | Format-Table -AutoSize
```
**输出**：  

```
InstanceId          InstanceType Platform PrivateIpAddress Name         State
----------          ------------ -------- ---------------- ----         -----
i-05a9...f6c5f46e18 t3.medium             10.0.1.7         ec2-name-01  running
i-02cf...945c4fdd07 t3.medium    Windows  10.0.1.8         ec2-name-02  stopped
i-0ac0...c037f9f3a1 t3.xlarge    Windows  10.0.1.10        ec2-name-03  running
i-066b...57b7b08888 t3.medium    Windows  10.0.1.11        ec2-name-04  stopped
i-0fee...82e83ccd72 t3.medium    Windows  10.0.1.5         ec2-name-05  running
i-0a68...274cc5043b t3.medium    Windows  10.0.1.6         ec2-name-06  stopped
```
**示例 6：此示例验证了在不实际获取 EC2 实例的情况下使用 DryRun 参数获取实例的权限。注：这在操作成功时会引发异常，这是预期行为。**  

```
Get-EC2Tag -DryRun $true
```
**输出**：  

```
Get-EC2Instance: Request would have succeeded, but DryRun flag is set.
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2InstanceAttribute`
<a name="ec2_DescribeInstanceAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2InstanceAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定实例的实例类型。**  

```
Get-EC2InstanceAttribute -InstanceId i-12345678 -Attribute instanceType
```
**输出**：  

```
InstanceType                      : t2.micro
```
**示例 2：此示例描述是否为指定实例启用增强联网。**  

```
Get-EC2InstanceAttribute -InstanceId i-12345678 -Attribute sriovNetSupport
```
**输出**：  

```
SriovNetSupport                   : simple
```
**示例 3：此示例描述指定实例的安全组。**  

```
(Get-EC2InstanceAttribute -InstanceId i-12345678 -Attribute groupSet).Groups
```
**输出**：  

```
GroupId
-------
sg-12345678
sg-45678901
```
**示例 4：此示例描述是否为指定的实例启用 EBS 优化。**  

```
Get-EC2InstanceAttribute -InstanceId i-12345678 -Attribute ebsOptimized
```
**输出**：  

```
EbsOptimized                      : False
```
**示例 5：此示例描述了指定实例disableApiTermination的 “” 属性。**  

```
Get-EC2InstanceAttribute -InstanceId i-12345678 -Attribute disableApiTermination
```
**输出**：  

```
DisableApiTermination             : False
```
**示例 6：此示例描述了指定实例instanceInitiatedShutdown的 “行为” 属性。**  

```
Get-EC2InstanceAttribute -InstanceId i-12345678 -Attribute instanceInitiatedShutdownBehavior
```
**输出**：  

```
InstanceInitiatedShutdownBehavior : stop
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeInstanceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2InstanceMetadata`
<a name="ec2_Get-EC2InstanceMetadata_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2InstanceMetadata`。

**适用于 PowerShell V5 的工具**  
**示例 1：列出可查询的可用实例元数据类别。**  

```
Get-EC2InstanceMetadata -ListCategory
```
**输出**：  

```
AmiId
LaunchIndex
ManifestPath
AncestorAmiId
BlockDeviceMapping
InstanceId
InstanceType
LocalHostname
LocalIpv4
KernelId
AvailabilityZone
ProductCode
PublicHostname
PublicIpv4
PublicKey
RamdiskId
Region
ReservationId
SecurityGroup
UserData
InstanceMonitoring
IdentityDocument
IdentitySignature
IdentityPkcs7
```
**示例 2：返回用于启动实例的亚马逊机器映像（AMI）的 ID。**  

```
Get-EC2InstanceMetadata -Category AmiId
```
**输出**：  

```
ami-b2e756ca
```
**示例 3：此示例查询实例的 JSON 格式的身份文档。**  

```
Get-EC2InstanceMetadata -Category IdentityDocument
{
  "availabilityZone" : "us-west-2a",
  "devpayProductCodes" : null,
  "marketplaceProductCodes" : null,
  "version" : "2017-09-30",
  "instanceId" : "i-01ed50f7e2607f09e",
  "billingProducts" : [ "bp-6ba54002" ],
  "instanceType" : "t2.small",
  "pendingTime" : "2018-03-07T16:26:04Z",
  "imageId" : "ami-b2e756ca",
  "privateIp" : "10.0.0.171",
  "accountId" : "111122223333",
  "architecture" : "x86_64",
  "kernelId" : null,
  "ramdiskId" : null,
  "region" : "us-west-2"
}
```
**示例 4：此示例使用路径查询来获取实例的网络接口 mac。**  

```
Get-EC2InstanceMetadata -Path "/network/interfaces/macs"
```
**输出**：  

```
02:80:7f:ef:4c:e0/
```
**示例 5：如果存在与该实例关联的 IAM 角色，则返回有关上次更新实例配置文件的时间的信息，包括实例的 LastUpdated 日期 InstanceProfileArn、和 InstanceProfileId。**  

```
Get-EC2InstanceMetadata -Path "/iam/info"
```
**输出**：  

```
{
  "Code" : "Success",
  "LastUpdated" : "2018-03-08T03:38:40Z",
  "InstanceProfileArn" : "arn:aws:iam::111122223333:instance-profile/MyLaunchRole_Profile",
  "InstanceProfileId" : "AIPAI4...WVK2RW"
}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [Get-EC2InstanceMetadata](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2InstanceStatus`
<a name="ec2_DescribeInstanceStatus_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2InstanceStatus`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定实例的状态。**  

```
Get-EC2InstanceStatus -InstanceId i-12345678
```
**输出**：  

```
AvailabilityZone : us-west-2a
Events           : {}
InstanceId       : i-12345678
InstanceState    : Amazon.EC2.Model.InstanceState
Status           : Amazon.EC2.Model.InstanceStatusSummary
SystemStatus     : Amazon.EC2.Model.InstanceStatusSummary
```

```
$status = Get-EC2InstanceStatus -InstanceId i-12345678
$status.InstanceState
```
**输出**：  

```
Code    Name
----    ----
16      running
```

```
$status.Status
```
**输出**：  

```
Details           Status
-------           ------
{reachability}    ok
```

```
$status.SystemStatus
```
**输出**：  

```
Details           Status
-------           ------
{reachability}    ok
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeInstanceStatus](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2InternetGateway`
<a name="ec2_DescribeInternetGateways_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2InternetGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的互联网网关。**  

```
Get-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d
```
**输出**：  

```
Attachments       InternetGatewayId     Tags
-----------       -----------------     ----
{vpc-1a2b3c4d}    igw-1a2b3c4d          {}
```
**示例 2：此示例描述所有互联网网关。**  

```
Get-EC2InternetGateway
```
**输出**：  

```
Attachments       InternetGatewayId     Tags
-----------       -----------------     ----
{vpc-1a2b3c4d}    igw-1a2b3c4d          {}
{}                igw-2a3b4c5d          {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeInternetGateways](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2KeyPair`
<a name="ec2_DescribeKeyPairs_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2KeyPair`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的密钥对。**  

```
Get-EC2KeyPair -KeyName my-key-pair
```
**输出**：  

```
KeyFingerprint                                              KeyName
--------------                                              -------
1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f my-key-pair
```
**示例 2：此示例描述所有密钥对。**  

```
Get-EC2KeyPair
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeKeyPairs](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2NetworkAcl`
<a name="ec2_DescribeNetworkAcls_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2NetworkAcl`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的网络 ACL。**  

```
Get-EC2NetworkAcl -NetworkAclId acl-12345678
```
**输出**：  

```
Associations : {aclassoc-1a2b3c4d}
Entries      : {Amazon.EC2.Model.NetworkAclEntry, Amazon.EC2.Model.NetworkAclEntry}
IsDefault    : False
NetworkAclId : acl-12345678
Tags         : {Name}
VpcId        : vpc-12345678
```
**示例 2：此示例描述指定网络 ACL 的规则。**  

```
(Get-EC2NetworkAcl -NetworkAclId acl-12345678).Entries
```
**输出**：  

```
CidrBlock    : 0.0.0.0/0
Egress       : True
IcmpTypeCode :
PortRange    :
Protocol     : -1
RuleAction   : deny
RuleNumber   : 32767

CidrBlock    : 0.0.0.0/0
Egress       : False
IcmpTypeCode :
PortRange    :
Protocol     : -1
RuleAction   : deny
RuleNumber   : 32767
```
**示例 3：此示例描述了您的所有网络 ACLs。**  

```
Get-EC2NetworkAcl
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeNetworkAcls](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2NetworkInterface`
<a name="ec2_DescribeNetworkInterfaces_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2NetworkInterface`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的网络接口。**  

```
Get-EC2NetworkInterface -NetworkInterfaceId eni-12345678
```
**输出**：  

```
Association        :
Attachment         : Amazon.EC2.Model.NetworkInterfaceAttachment
AvailabilityZone   : us-west-2c
Description        :
Groups             : {my-security-group}
MacAddress         : 0a:e9:a6:19:4c:7f
NetworkInterfaceId : eni-12345678
OwnerId            : 123456789012
PrivateDnsName     : ip-10-0-0-107.us-west-2.compute.internal
PrivateIpAddress   : 10.0.0.107
PrivateIpAddresses : {ip-10-0-0-107.us-west-2.compute.internal}
RequesterId        :
RequesterManaged   : False
SourceDestCheck    : True
Status             : in-use
SubnetId           : subnet-1a2b3c4d
TagSet             : {}
VpcId              : vpc-12345678
```
**示例 2：此示例描述所有网络接口。**  

```
Get-EC2NetworkInterface
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeNetworkInterfaces](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2NetworkInterfaceAttribute`
<a name="ec2_DescribeNetworkInterfaceAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2NetworkInterfaceAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的网络接口。**  

```
Get-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-12345678 -Attribute Attachment
```
**输出**：  

```
Attachment         : Amazon.EC2.Model.NetworkInterfaceAttachment
```
**示例 2：此示例描述指定的网络接口。**  

```
Get-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-12345678 -Attribute Description
```
**输出**：  

```
Description        : My description
```
**示例 3：此示例描述指定的网络接口。**  

```
Get-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-12345678 -Attribute GroupSet
```
**输出**：  

```
Groups             : {my-security-group}
```
**示例 4：此示例描述指定的网络接口。**  

```
Get-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-12345678 -Attribute SourceDestCheck
```
**输出**：  

```
SourceDestCheck    : True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeNetworkInterfaceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2PasswordData`
<a name="ec2_GetPasswordData_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2PasswordData`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例解密亚马逊为指定 Windows 实例的管理员账户 EC2 分配的密码。当指定了 pem 文件时，将自动假定 -Decrypt 开关的设置。**  

```
Get-EC2PasswordData -InstanceId i-12345678 -PemFile C:\path\my-key-pair.pem
```
**输出**：  

```
mYZ(PA9?C)Q
```
**示例 2：（ PowerShell 仅限 Windows）检查实例以确定用于启动实例的密钥对的名称，然后尝试在 Visual Studio T AWS oolkit for Visual Studio 的配置存储中查找相应的密钥对数据。如果找到了密钥对数据，则对密码进行解密。**  

```
Get-EC2PasswordData -InstanceId i-12345678 -Decrypt
```
**输出**：  

```
mYZ(PA9?C)Q
```
**示例 3：返回实例的已加密密码数据。**  

```
Get-EC2PasswordData -InstanceId i-12345678
```
**输出**：  

```
iVz3BAK/WAXV.....dqt8WeMA==
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetPasswordData](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2PlacementGroup`
<a name="ec2_DescribePlacementGroups_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2PlacementGroup`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的置放群组。**  

```
Get-EC2PlacementGroup -GroupName my-placement-group
```
**输出**：  

```
GroupName             State        Strategy
---------             -----        --------
my-placement-group    available    cluster
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribePlacementGroups](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2PrefixList`
<a name="ec2_DescribePrefixLists_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2PrefixList`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例以前缀列表格式获取该区域的可用 AWS 服务 内容**  

```
Get-EC2PrefixList
```
**输出**：  

```
Cidrs                                          PrefixListId PrefixListName
-----                                          ------------ --------------
{52.94.5.0/24, 52.119.240.0/21, 52.94.24.0/23} pl-6fa54006  com.amazonaws.eu-west-1.dynamodb
{52.218.0.0/17, 54.231.128.0/19}               pl-6da54004  com.amazonaws.eu-west-1.s3
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribePrefixLists](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Region`
<a name="ec2_DescribeRegions_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Region`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述可供您使用的区域。**  

```
Get-EC2Region
```
**输出**：  

```
Endpoint                            RegionName
--------                            ----------
ec2.eu-west-1.amazonaws.com         eu-west-1
ec2.ap-southeast-1.amazonaws.com    ap-southeast-1
ec2.ap-southeast-2.amazonaws.com    ap-southeast-2
ec2.eu-central-1.amazonaws.com      eu-central-1
ec2.ap-northeast-1.amazonaws.com    ap-northeast-1
ec2.us-east-1.amazonaws.com         us-east-1
ec2.sa-east-1.amazonaws.com         sa-east-1
ec2.us-west-1.amazonaws.com         us-west-1
ec2.us-west-2.amazonaws.com         us-west-2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeRegions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2RouteTable`
<a name="ec2_DescribeRouteTables_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2RouteTable`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述所有路由表。**  

```
Get-EC2RouteTable
```
**输出**：  

```
DestinationCidrBlock    : 10.0.0.0/16
DestinationPrefixListId :
GatewayId               : local
InstanceId              :
InstanceOwnerId         :
NetworkInterfaceId      :
Origin                  : CreateRouteTable
State                   : active
VpcPeeringConnectionId  :

DestinationCidrBlock    : 0.0.0.0/0
DestinationPrefixListId :
GatewayId               : igw-1a2b3c4d
InstanceId              :
InstanceOwnerId         :
NetworkInterfaceId      :
Origin                  : CreateRoute
State                   : active
VpcPeeringConnectionId  :
```
**示例 2：此示例返回指定路由表的详细信息。**  

```
Get-EC2RouteTable -RouteTableId rtb-1a2b3c4d
```
**示例 3：此示例描述指定 VPC 的路由表。**  

```
Get-EC2RouteTable -Filter @{ Name="vpc-id"; Values="vpc-1a2b3c4d" }
```
**输出**：  

```
Associations    : {rtbassoc-12345678}
PropagatingVgws : {}
Routes          : {, }
RouteTableId    : rtb-1a2b3c4d
Tags            : {}
VpcId           : vpc-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeRouteTables](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2ScheduledInstance`
<a name="ec2_DescribeScheduledInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2ScheduledInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的计划实例。**  

```
Get-EC2ScheduledInstance -ScheduledInstanceId sci-1234-1234-1234-1234-123456789012
```
**输出**：  

```
AvailabilityZone            : us-west-2b
CreateDate                  : 1/25/2016 1:43:38 PM
HourlyPrice                 : 0.095
InstanceCount               : 1
InstanceType                : c4.large
NetworkPlatform             : EC2-VPC
NextSlotStartTime           : 1/31/2016 1:00:00 AM
Platform                    : Linux/UNIX
PreviousSlotEndTime         : 
Recurrence                  : Amazon.EC2.Model.ScheduledInstanceRecurrence
ScheduledInstanceId         : sci-1234-1234-1234-1234-123456789012
SlotDurationInHours         : 32
TermEndDate                 : 1/31/2017 1:00:00 AM
TermStartDate               : 1/31/2016 1:00:00 AM
TotalScheduledInstanceHours : 1696
```
**示例 2：此示例描述所有计划实例。**  

```
Get-EC2ScheduledInstance
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeScheduledInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2ScheduledInstanceAvailability`
<a name="ec2_DescribeScheduledInstanceAvailability_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2ScheduledInstanceAvailability`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述从指定日期开始每周星期日发生的计划。**  

```
Get-EC2ScheduledInstanceAvailability -Recurrence_Frequency Weekly -Recurrence_Interval 1 -Recurrence_OccurrenceDay 1 -FirstSlotStartTimeRange_EarliestTime 2016-01-31T00:00:00Z -FirstSlotStartTimeRange_LatestTime 2016-01-31T04:00:00Z
```
**输出**：  

```
AvailabilityZone            : us-west-2b
AvailableInstanceCount      : 20
FirstSlotStartTime          : 1/31/2016 8:00:00 AM
HourlyPrice                 : 0.095
InstanceType                : c4.large
MaxTermDurationInDays       : 366
MinTermDurationInDays       : 366
NetworkPlatform             : EC2-VPC
Platform                    : Linux/UNIX
PurchaseToken               : eyJ2IjoiMSIsInMiOjEsImMiOi...
Recurrence                  : Amazon.EC2.Model.ScheduledInstanceRecurrence
SlotDurationInHours         : 23
TotalScheduledInstanceHours : 1219

...
```
**示例 2：要缩小结果范围，您可以为操作系统、网络和实例类型等条件添加筛选条件。**  

```
-Filter @{ Name="platform";Values="Linux/UNIX" },@{ Name="network-platform";Values="EC2-VPC" },@{ Name="instance-type";Values="c4.large" }
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeScheduledInstanceAvailability](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SecurityGroup`
<a name="ec2_DescribeSecurityGroups_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SecurityGroup`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述 VPC 的指定安全组。使用属于 VPC 的安全组时，必须使用安全组 ID（-GroupId 参数），而不是名称（-GroupName 参数）来引用该组。**  

```
Get-EC2SecurityGroup -GroupId sg-12345678
```
**输出**：  

```
Description         : default VPC security group
GroupId             : sg-12345678
GroupName           : default
IpPermissions       : {Amazon.EC2.Model.IpPermission}
IpPermissionsEgress : {Amazon.EC2.Model.IpPermission}
OwnerId             : 123456789012
Tags                : {}
VpcId               : vpc-12345678
```
**示例 2：此示例描述了 EC2-Classic 的指定安全组。在 EC2-Classic 中使用安全组时，您可以使用组名称（-GroupName 参数）或组 ID（-GroupId 参数）来引用安全组。**  

```
Get-EC2SecurityGroup -GroupName my-security-group
```
**输出**：  

```
Description         : my security group
GroupId             : sg-45678901
GroupName           : my-security-group
IpPermissions       : {Amazon.EC2.Model.IpPermission, Amazon.EC2.Model.IpPermission}
IpPermissionsEgress : {}
OwnerId             : 123456789012
Tags                : {}
VpcId               :
```
**示例 3：此示例检索 vpc-0fc1ff23456b789eb 的所有安全组**  

```
Get-EC2SecurityGroup -Filter @{Name="vpc-id";Values="vpc-0fc1ff23456b789eb"}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSecurityGroups](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Snapshot`
<a name="ec2_DescribeSnapshots_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Snapshot`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的快照。**  

```
Get-EC2Snapshot -SnapshotId snap-12345678
```
**输出**：  

```
DataEncryptionKeyId :
Description         : Created by CreateImage(i-1a2b3c4d) for ami-12345678 from vol-12345678
Encrypted           : False
KmsKeyId            :
OwnerAlias          :
OwnerId             : 123456789012
Progress            : 100%
SnapshotId          : snap-12345678
StartTime           : 10/23/2014 6:01:28 AM
State               : completed
StateMessage        :
Tags                : {}
VolumeId            : vol-12345678
VolumeSize          : 8
```
**示例 2：此示例描述具有“Name”标签的快照。**  

```
Get-EC2Snapshot | ? { $_.Tags.Count -gt 0 -and $_.Tags.Key -eq "Name" }
```
**示例 3：此示例描述了带有 “名称” 标签且值为 “TestValue” 的快照。**  

```
Get-EC2Snapshot | ? { $_.Tags.Count -gt 0 -and $_.Tags.Key -eq "Name" -and $_.Tags.Value -eq "TestValue" }
```
**示例 4：此示例描述所有快照。**  

```
Get-EC2Snapshot -Owner self
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSnapshots](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SnapshotAttribute`
<a name="ec2_DescribeSnapshotAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SnapshotAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定快照的指定属性。**  

```
Get-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute ProductCodes
```
**输出**：  

```
CreateVolumePermissions    ProductCodes    SnapshotId
-----------------------    ------------    ----------
{}                         {}              snap-12345678
```
**示例 2：此示例描述指定快照的指定属性。**  

```
(Get-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute CreateVolumePermission).CreateVolumePermissions
```
**输出**：  

```
Group    UserId
-----    ------
all
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSnapshotAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SpotDatafeedSubscription`
<a name="ec2_DescribeSpotDatafeedSubscription_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SpotDatafeedSubscription`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述竞价型实例数据源。**  

```
Get-EC2SpotDatafeedSubscription
```
**输出**：  

```
Bucket  : amzn-s3-demo-bucket
Fault   :
OwnerId : 123456789012
Prefix  : spotdata
State   : Active
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SpotFleetInstance`
<a name="ec2_DescribeSpotFleetInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SpotFleetInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述与指定竞价型实例集请求关联的实例。**  

```
Get-EC2SpotFleetInstance -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE
```
**输出**：  

```
InstanceId    InstanceType    SpotInstanceRequestId
----------    ------------    ---------------------
i-f089262a    c3.large        sir-12345678
i-7e8b24a4    c3.large        sir-87654321
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSpotFleetInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SpotFleetRequest`
<a name="ec2_DescribeSpotFleetRequests_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SpotFleetRequest`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的竞价型实例集请求。**  

```
Get-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE | format-list
```
**输出**：  

```
ConfigData            : Amazon.EC2.Model.SpotFleetRequestConfigData
CreateTime            : 12/26/2015 8:23:33 AM
SpotFleetRequestId    : sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE
SpotFleetRequestState : active
```
**示例 2：此示例描述所有竞价型实例集请求。**  

```
Get-EC2SpotFleetRequest
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSpotFleetRequests](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SpotFleetRequestHistory`
<a name="ec2_DescribeSpotFleetRequestHistory_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SpotFleetRequestHistory`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的竞价型实例集请求的历史记录。**  

```
Get-EC2SpotFleetRequestHistory -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -StartTime 2015-12-26T00:00:00Z
```
**输出**：  

```
HistoryRecords     : {Amazon.EC2.Model.HistoryRecord, Amazon.EC2.Model.HistoryRecord...}
LastEvaluatedTime  : 12/26/2015 8:29:11 AM
NextToken          :
SpotFleetRequestId : sfr-088bc5f1-7e7b-451a-bd13-757f10672b93
StartTime          : 12/25/2015 8:00:00 AM
```

```
(Get-EC2SpotFleetRequestHistory -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -StartTime 2015-12-26T00:00:00Z).HistoryRecords
```
**输出**：  

```
EventInformation                     EventType             Timestamp
----------------                     ---------             ---------
Amazon.EC2.Model.EventInformation    fleetRequestChange    12/26/2015 8:23:33 AM
Amazon.EC2.Model.EventInformation    fleetRequestChange    12/26/2015 8:23:33 AM
Amazon.EC2.Model.EventInformation    fleetRequestChange    12/26/2015 8:23:33 AM
Amazon.EC2.Model.EventInformation    launched              12/26/2015 8:25:34 AM
Amazon.EC2.Model.EventInformation    launched              12/26/2015 8:25:05 AM
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSpotFleetRequestHistory](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SpotInstanceRequest`
<a name="ec2_DescribeSpotInstanceRequests_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SpotInstanceRequest`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的竞价型实例请求。**  

```
Get-EC2SpotInstanceRequest -SpotInstanceRequestId sir-12345678
```
**输出**：  

```
ActualBlockHourlyPrice   :
AvailabilityZoneGroup    :
BlockDurationMinutes     : 0
CreateTime               : 4/8/2015 2:51:33 PM
Fault                    :
InstanceId               : i-12345678
LaunchedAvailabilityZone : us-west-2b
LaunchGroup              :
LaunchSpecification      : Amazon.EC2.Model.LaunchSpecification
ProductDescription       : Linux/UNIX
SpotInstanceRequestId    : sir-12345678
SpotPrice                : 0.020000
State                    : active
Status                   : Amazon.EC2.Model.SpotInstanceStatus
Tags                     : {Name}
Type                     : one-time
```
**示例 2：此示例描述所有竞价型实例请求。**  

```
Get-EC2SpotInstanceRequest
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSpotInstanceRequests](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2SpotPriceHistory`
<a name="ec2_DescribeSpotPriceHistory_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2SpotPriceHistory`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取指定实例类型和可用区的竞价价格历史记录中的最后 10 个条目。请注意，为-AvailabilityZone 参数指定的值必须对提供给 cmdlet 的-Region 参数（示例中未显示）的区域值有效，或者在 shell 中设置为默认值。此示例命令假设环境中已设置了默认区域“us-west-2”。**  

```
Get-EC2SpotPriceHistory -InstanceType c3.large -AvailabilityZone us-west-2a -MaxResult 10
```
**输出**：  

```
AvailabilityZone   : us-west-2a
InstanceType       : c3.large
Price              : 0.017300
ProductDescription : Linux/UNIX (Amazon VPC)
Timestamp          : 12/25/2015 7:39:49 AM

AvailabilityZone   : us-west-2a
InstanceType       : c3.large
Price              : 0.017200
ProductDescription : Linux/UNIX (Amazon VPC)
Timestamp          : 12/25/2015 7:38:29 AM

AvailabilityZone   : us-west-2a
InstanceType       : c3.large
Price              : 0.017300
ProductDescription : Linux/UNIX (Amazon VPC)
Timestamp          : 12/25/2015 6:57:13 AM
...
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSpotPriceHistory](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Subnet`
<a name="ec2_DescribeSubnets_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Subnet`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的子网。**  

```
Get-EC2Subnet -SubnetId subnet-1a2b3c4d
```
**输出**：  

```
AvailabilityZone        : us-west-2c
AvailableIpAddressCount : 251
CidrBlock               : 10.0.0.0/24
DefaultForAz            : False
MapPublicIpOnLaunch     : False
State                   : available
SubnetId                : subnet-1a2b3c4d
Tags                    : {}
VpcId                   : vpc-12345678
```
**示例 2：此示例描述所有子网。**  

```
Get-EC2Subnet
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeSubnets](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Tag`
<a name="ec2_DescribeTags_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Tag`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取资源类型“image”的标签**  

```
Get-EC2Tag -Filter @{Name="resource-type";Values="image"}
```
**输出**：  

```
Key         ResourceId            ResourceType Value
---         ----------            ------------ -----
Name        ami-0a123b4ccb567a8ea image        Win7-Imported
auto-delete ami-0a123b4ccb567a8ea image        never
```
**示例 2：此示例获取所有资源的所有标签，并按资源类型对它们进行分组**  

```
Get-EC2Tag | Group-Object resourcetype
```
**输出**：  

```
Count Name                      Group
----- ----                      -----
    9 subnet                    {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
   53 instance                  {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
    3 route-table               {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
    5 security-group            {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
   30 volume                    {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
    1 internet-gateway          {Amazon.EC2.Model.TagDescription}
    3 network-interface         {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
    4 elastic-ip                {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
    1 dhcp-options              {Amazon.EC2.Model.TagDescription}
    2 image                     {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
    3 vpc                       {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
```
**示例 3：此示例显示给定区域中所有带有“auto-delete”标签且值为“no”的资源**  

```
Get-EC2Tag -Region eu-west-1 -Filter @{Name="tag:auto-delete";Values="no"}
```
**输出**：  

```
Key         ResourceId            ResourceType Value
---         ----------            ------------ -----
auto-delete i-0f1bce234d5dd678b   instance     no
auto-delete vol-01d234aa5678901a2 volume       no
auto-delete vol-01234bfb5def6f7b8 volume       no
auto-delete vol-01ccb23f4c5e67890 volume       no
```
**示例 4：此示例获取所有带有 “auto-delete” 标签且值为 “无” 的资源，并在下一个管道中进行进一步筛选以仅解析 “实例” 资源类型，最终为每个实例资源创建 ThisInstance “” 标签，其值为实例 ID 本身**  

```
Get-EC2Tag -Region eu-west-1 -Filter @{Name="tag:auto-delete";Values="no"} | Where-Object ResourceType -eq "instance" | ForEach-Object {New-EC2Tag -ResourceId $_.ResourceId -Tag @{Key="ThisInstance";Value=$_.ResourceId}}
```
**示例 5：此示例获取所有实例资源的标签以及“Name”键并以表格式显示它们**  

```
Get-EC2Tag -Filter @{Name="resource-type";Values="instance"},@{Name="key";Values="Name"} | Select-Object ResourceId, @{Name="Name-Tag";Expression={$PSItem.Value}} | Format-Table -AutoSize
```
**输出**：  

```
ResourceId          Name-Tag
----------          --------
i-012e3cb4df567e1aa jump1
i-01c23a45d6fc7a89f repro-3
```
**示例 6：此示例验证使用 DryRun 参数获取 EC2 标签的权限，而无需实际获取标签。注：这在操作成功时会引发异常，这是预期行为。**  

```
Get-EC2Tag -DryRun $true
```
**输出**：  

```
Get-EC2Tag: Request would have succeeded, but DryRun flag is set.
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeTags](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Volume`
<a name="ec2_DescribeVolumes_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Volume`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的 EBS 卷。**  

```
Get-EC2Volume -VolumeId vol-12345678
```
**输出**：  

```
Attachments      : {}
AvailabilityZone : us-west-2c
CreateTime       : 7/17/2015 4:35:19 PM
Encrypted        : False
Iops             : 90
KmsKeyId         :
Size             : 30
SnapshotId       : snap-12345678
State            : in-use
Tags             : {}
VolumeId         : vol-12345678
VolumeType       : standard
```
**示例 2：此示例描述状态为“可用”的 EBS 卷。**  

```
Get-EC2Volume -Filter @{ Name="status"; Values="available" }
```
**输出**：  

```
Attachments      : {}
AvailabilityZone : us-west-2c
CreateTime       : 12/21/2015 2:31:29 PM
Encrypted        : False
Iops             : 60
KmsKeyId         :
Size             : 20
SnapshotId       : snap-12345678
State            : available
Tags             : {}
VolumeId         : vol-12345678
VolumeType       : gp2
...
```
**示例 3：此示例描述所有 EBS 卷。**  

```
Get-EC2Volume
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVolumes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VolumeAttribute`
<a name="ec2_DescribeVolumeAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VolumeAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定卷的指定属性。**  

```
Get-EC2VolumeAttribute -VolumeId vol-12345678 -Attribute AutoEnableIO
```
**输出**：  

```
AutoEnableIO    ProductCodes    VolumeId
------------    ------------    --------
False           {}              vol-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVolumeAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VolumeStatus`
<a name="ec2_DescribeVolumeStatus_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VolumeStatus`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定卷的状态。**  

```
Get-EC2VolumeStatus -VolumeId vol-12345678
```
**输出**：  

```
Actions          : {}
AvailabilityZone : us-west-2a
Events           : {}
VolumeId         : vol-12345678
VolumeStatus     : Amazon.EC2.Model.VolumeStatusInfo
```

```
(Get-EC2VolumeStatus -VolumeId vol-12345678).VolumeStatus
```
**输出**：  

```
Details                         Status
-------                         ------
{io-enabled, io-performance}    ok
```

```
(Get-EC2VolumeStatus -VolumeId vol-12345678).VolumeStatus.Details
```
**输出**：  

```
Name                            Status
----                            ------
io-enabled                      passed
io-performance                  not-applicable
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVolumeStatus](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2Vpc`
<a name="ec2_DescribeVpcs_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2Vpc`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的 VPC。**  

```
Get-EC2Vpc -VpcId vpc-12345678
```
**输出**：  

```
CidrBlock       : 10.0.0.0/16
DhcpOptionsId   : dopt-1a2b3c4d
InstanceTenancy : default
IsDefault       : False
State           : available
Tags            : {Name}
VpcId           : vpc-12345678
```
**示例 2：此示例描述默认 VPC（每个区域只能有一个）。如果您的账户在此区域支持 EC2-Classic，则没有默认 VPC。**  

```
Get-EC2Vpc -Filter @{Name="isDefault"; Values="true"}
```
**输出**：  

```
CidrBlock       : 172.31.0.0/16
DhcpOptionsId   : dopt-12345678
InstanceTenancy : default
IsDefault       : True
State           : available
Tags            : {}
VpcId           : vpc-45678901
```
**示例 3：此示例描述了 VPCs 与指定过滤器匹配的（即，具有与值 “10.0.0.0/16” 匹配且处于 “可用” 状态的 CIDR）。**  

```
Get-EC2Vpc -Filter @{Name="cidr"; Values="10.0.0.0/16"},@{Name="state";Values="available"}
```
**示例 4: 此示例描述了您的所有内容 VPCs.**  

```
Get-EC2Vpc
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpcs](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpcAttribute`
<a name="ec2_DescribeVpcAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpcAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了 “enableDnsSupport” 属性。**  

```
Get-EC2VpcAttribute -VpcId vpc-12345678 -Attribute enableDnsSupport
```
**输出**：  

```
EnableDnsSupport
----------------
True
```
**示例 2：此示例描述了 “enableDnsHostnames” 属性。**  

```
Get-EC2VpcAttribute -VpcId vpc-12345678 -Attribute enableDnsHostnames
```
**输出**：  

```
EnableDnsHostnames
------------------
True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpcAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpcClassicLink`
<a name="ec2_DescribeVpcClassicLink_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpcClassicLink`。

**适用于 PowerShell V5 的工具**  
**示例 1：上面的示例返回 VPCs 了该区域的所有及其 ClassicLinkEnabled 状态**  

```
Get-EC2VpcClassicLink -Region eu-west-1
```
**输出**：  

```
ClassicLinkEnabled Tags   VpcId
------------------ ----   -----
False              {Name} vpc-0fc1ff23f45b678eb
False              {}     vpc-01e23c4a5d6db78e9
False              {Name} vpc-0123456b078b9d01f
False              {}     vpc-12cf3b4f
False              {Name} vpc-0b12d3456a7e8901d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpcClassicLink](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpcClassicLinkDnsSupport`
<a name="ec2_DescribeVpcClassicLinkDnsSupport_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpcClassicLinkDnsSupport`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了 eu-west-1 区域 VPCs 的 ClassicLink DNS 支持状态**  

```
Get-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d -Region eu-west-1
```
**输出**：  

```
ClassicLinkDnsSupported VpcId
----------------------- -----
False                   vpc-0b12d3456a7e8910d
False                   vpc-12cf3b4f
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpcClassicLinkDnsSupport](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpcEndpoint`
<a name="ec2_DescribeVpcEndpoints_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpcEndpoint`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述区域 eu-west-1 的一个或多个 VPC 端点。然后，它将输出通过管道传递给下一个命令，该命令选择 VpcEndpointId 属性并以字符串数组的形式返回数组 VPC ID**  

```
Get-EC2VpcEndpoint -Region eu-west-1 | Select-Object -ExpandProperty VpcEndpointId
```
**输出**：  

```
vpce-01a2ab3f4f5cc6f7d
vpce-01d2b345a6787890b
vpce-0012e34d567890e12
vpce-0c123db4567890123
```
**示例 2：此示例描述了 eu-west-1 区域的所有 vpc 终端节点，并 VpcEndpointId选择 VpcId ServiceName 、 PrivateDnsEnabled 和属性以表格格式呈现该终端节点**  

```
Get-EC2VpcEndpoint -Region eu-west-1 | Select-Object VpcEndpointId, VpcId, ServiceName, PrivateDnsEnabled | Format-Table -AutoSize
```
**输出**：  

```
VpcEndpointId          VpcId                 ServiceName                         PrivateDnsEnabled
-------------          -----                 -----------                         -----------------
vpce-02a2ab2f2f2cc2f2d vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ssm                      True
vpce-01d1b111a1114561b vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ec2                      True
vpce-0011e23d45167e838 vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ec2messages              True
vpce-0c123db4567890123 vpc-0fc6ff46f65b039eb com.amazonaws.eu-west-1.ssmmessages              True
```
**示例 3：此示例将 VPC 端点 vpce-01a2ab3f4f5cc6f7d 的策略文档导出到 json 文件中**  

```
Get-EC2VpcEndpoint -Region eu-west-1 -VpcEndpointId vpce-01a2ab3f4f5cc6f7d | Select-Object -expand PolicyDocument | Out-File vpce_policyDocument.json
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpcEndpoints](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpcEndpointService`
<a name="ec2_DescribeVpcEndpointServices_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpcEndpointService`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了使用给定筛选条件的 EC2 VPC 终端节点服务，在本例中为 com.amazonaws.eu-west-1.ecs。此外，它还会扩展 ServiceDetails 属性并显示细节**  

```
Get-EC2VpcEndpointService -Region eu-west-1 -MaxResult 5 -Filter @{Name="service-name";Values="com.amazonaws.eu-west-1.ecs"} | Select-Object -ExpandProperty ServiceDetails
```
**输出**：  

```
AcceptanceRequired         : False
AvailabilityZones          : {eu-west-1a, eu-west-1b, eu-west-1c}
BaseEndpointDnsNames       : {ecs.eu-west-1.vpce.amazonaws.com}
Owner                      : amazon
PrivateDnsName             : ecs.eu-west-1.amazonaws.com
ServiceName                : com.amazonaws.eu-west-1.ecs
ServiceType                : {Amazon.EC2.Model.ServiceTypeDetail}
VpcEndpointPolicySupported : False
```
**示例 2：此示例检索所有 EC2 VPC 终端节点服务并返回 ServiceNames 匹配的 “ssm”**  

```
Get-EC2VpcEndpointService -Region eu-west-1 | Select-Object -ExpandProperty Servicenames | Where-Object { -match "ssm"}
```
**输出**：  

```
com.amazonaws.eu-west-1.ssm
com.amazonaws.eu-west-1.ssmmessages
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpcEndpointServices](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpnConnection`
<a name="ec2_DescribeVpnConnections_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpnConnection`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的 VPN 连接。**  

```
Get-EC2VpnConnection -VpnConnectionId vpn-12345678
```
**输出**：  

```
CustomerGatewayConfiguration : [XML document]
CustomerGatewayId            : cgw-1a2b3c4d
Options                      : Amazon.EC2.Model.VpnConnectionOptions
Routes                       : {Amazon.EC2.Model.VpnStaticRoute}
State                        : available
Tags                         : {}
Type                         : ipsec.1
VgwTelemetry                 : {Amazon.EC2.Model.VgwTelemetry, Amazon.EC2.Model.VgwTelemetry}
VpnConnectionId              : vpn-12345678
VpnGatewayId                 : vgw-1a2b3c4d
```
**示例 2：此示例描述状态为待定或可用的任何 VPN 连接。**  

```
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = "state"
$filter.Values = @( "pending", "available" )

Get-EC2VpnConnection -Filter $filter
```
**示例 3：此示例描述所有 VPN 连接。**  

```
Get-EC2VpnConnection
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpnConnections](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EC2VpnGateway`
<a name="ec2_DescribeVpnGateways_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-EC2VpnGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的虚拟专用网关。**  

```
Get-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d
```
**输出**：  

```
AvailabilityZone :
State            : available
Tags             : {}
Type             : ipsec.1
VpcAttachments   : {vpc-12345678}
VpnGatewayId     : vgw-1a2b3c4d
```
**示例 2：此示例描述状态为待定或可用的所有虚拟专用网关。**  

```
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = "state"
$filter.Values = @( "pending", "available" )

Get-EC2VpnGateway -Filter $filter
```
**示例 3：此示例描述所有虚拟专用网关。**  

```
Get-EC2VpnGateway
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeVpnGateways](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Grant-EC2SecurityGroupEgress`
<a name="ec2_AuthorizeSecurityGroupEgress_powershell_topic"></a>

以下代码示例演示了如何使用 `Grant-EC2SecurityGroupEgress`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为 EC2-VPC 的指定安全组定义了出口规则。此规则授予对 TCP 端口 80 上指定 IP 地址范围的访问权限。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ip = @{ IpProtocol="tcp"; FromPort="80"; ToPort="80"; IpRanges="203.0.113.0/24" }
Grant-EC2SecurityGroupEgress -GroupId sg-12345678 -IpPermission $ip
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建对象。 IpPermission **  

```
$ip = New-Object Amazon.EC2.Model.IpPermission
$ip.IpProtocol = "tcp"
$ip.FromPort = 80
$ip.ToPort = 80
$ip.IpRanges.Add("203.0.113.0/24")

Grant-EC2SecurityGroupEgress -GroupId sg-12345678 -IpPermission $ip
```
**示例 3：此示例授予对 TCP 端口 80 上指定源安全组的访问权限。**  

```
$ug = New-Object Amazon.EC2.Model.UserIdGroupPair
$ug.GroupId = "sg-1a2b3c4d"
$ug.UserId = "123456789012"

Grant-EC2SecurityGroupEgress -GroupId sg-12345678 -IpPermission @( @{ IpProtocol="tcp"; FromPort="80"; ToPort="80"; UserIdGroupPairs=$ug } )
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AuthorizeSecurityGroupEgress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Grant-EC2SecurityGroupIngress`
<a name="ec2_AuthorizeSecurityGroupIngress_powershell_topic"></a>

以下代码示例演示了如何使用 `Grant-EC2SecurityGroupIngress`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例定义了 EC2-VPC 安全组的入口规则。这些规则为 SSH（端口 22）和 RDC（端口 3389）授予对特定 IP 地址的访问权限。请注意，您必须使用安全组 ID 而不是安全组名称来识别 EC2-VPC 的安全组。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ip1 = @{ IpProtocol="tcp"; FromPort="22"; ToPort="22"; IpRanges="203.0.113.25/32" }
$ip2 = @{ IpProtocol="tcp"; FromPort="3389"; ToPort="3389"; IpRanges="203.0.113.25/32" }

Grant-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission @( $ip1, $ip2 )
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建对象。 IpPermission **  

```
$ip1 = New-Object Amazon.EC2.Model.IpPermission
$ip1.IpProtocol = "tcp"
$ip1.FromPort = 22
$ip1.ToPort = 22
$ip1.IpRanges.Add("203.0.113.25/32")

$ip2 = new-object Amazon.EC2.Model.IpPermission
$ip2.IpProtocol = "tcp"
$ip2.FromPort = 3389
$ip2.ToPort = 3389
$ip2.IpRanges.Add("203.0.113.25/32")

Grant-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission @( $ip1, $ip2 )
```
**示例 3：此示例定义了 EC2-Classic 安全组的入口规则。这些规则为 SSH（端口 22）和 RDC（端口 3389）授予对特定 IP 地址的访问权限。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ip1 = @{ IpProtocol="tcp"; FromPort="22"; ToPort="22"; IpRanges="203.0.113.25/32" }
$ip2 = @{ IpProtocol="tcp"; FromPort="3389"; ToPort="3389"; IpRanges="203.0.113.25/32" }

Grant-EC2SecurityGroupIngress -GroupName "my-security-group" -IpPermission @( $ip1, $ip2 )
```
**示例 4：在 PowerShell 版本 2 中，必须使用 New-Object 来创建对象。 IpPermission **  

```
$ip1 = New-Object Amazon.EC2.Model.IpPermission
$ip1.IpProtocol = "tcp"
$ip1.FromPort = 22
$ip1.ToPort = 22
$ip1.IpRanges.Add("203.0.113.25/32")

$ip2 = new-object Amazon.EC2.Model.IpPermission
$ip2.IpProtocol = "tcp"
$ip2.FromPort = 3389
$ip2.ToPort = 3389
$ip2.IpRanges.Add("203.0.113.25/32")

Grant-EC2SecurityGroupIngress -GroupName "my-security-group" -IpPermission @( $ip1, $ip2 )
```
**示例 5：此示例授予 TCP 端口 8081 从指定的源安全组（sg-1a2b3c4d）到指定的安全组（sg-12345678）的访问权限。**  

```
$ug = New-Object Amazon.EC2.Model.UserIdGroupPair
$ug.GroupId = "sg-1a2b3c4d"
$ug.UserId = "123456789012"

Grant-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission @( @{ IpProtocol="tcp"; FromPort="8081"; ToPort="8081"; UserIdGroupPairs=$ug } )
```
**示例 6：此示例将 CIDR 5.5.5.5/32 添加到 TCP 端口 22 流量的安全组 sg-1234abcd 的入口规则中，并附有描述。**  

```
$IpRange = New-Object -TypeName Amazon.EC2.Model.IpRange
$IpRange.CidrIp = "5.5.5.5/32"
$IpRange.Description = "SSH from Office"
$IpPermission = New-Object Amazon.EC2.Model.IpPermission
$IpPermission.IpProtocol = "tcp"
$IpPermission.ToPort = 22
$IpPermission.FromPort = 22
$IpPermission.Ipv4Ranges = $IpRange
Grant-EC2SecurityGroupIngress -GroupId sg-1234abcd -IpPermission $IpPermission
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AuthorizeSecurityGroupIngress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Import-EC2Image`
<a name="ec2_ImportImage_powershell_topic"></a>

以下代码示例演示了如何使用 `Import-EC2Image`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用等性令牌将单磁盘虚拟机映像从指定的 Amazon S3 存储桶导入到 EC2 Amazon。该示例要求存在默认名称为 “vmimport” 的虚拟机导入服务角色，其策略允许亚马逊 EC2 访问指定的存储桶，如虚拟机导入先决条件主题中所述。要使用自定义角色，请使用 `-RoleName` 参数指定角色名称。**  

```
$container = New-Object Amazon.EC2.Model.ImageDiskContainer
$container.Format="VMDK"
$container.UserBucket = New-Object Amazon.EC2.Model.UserBucket
$container.UserBucket.S3Bucket = "amzn-s3-demo-bucket"
$container.UserBucket.S3Key = "Win_2008_Server_Standard_SP2_64-bit-disk1.vmdk"

$parms = @{
    "ClientToken"="idempotencyToken"
    "Description"="Windows 2008 Standard Image Import"
    "Platform"="Windows"
    "LicenseType"="AWS"
}

Import-EC2Image -DiskContainer $container @parms
```
**输出**：  

```
Architecture    : 
Description     : Windows 2008 Standard Image
Hypervisor      : 
ImageId         : 
ImportTaskId    : import-ami-abcdefgh
LicenseType     : AWS
Platform        : Windows
Progress        : 2
SnapshotDetails : {}
Status          : active
StatusMessage   : pending
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ImportImage](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Import-EC2KeyPair`
<a name="ec2_ImportKeyPair_powershell_topic"></a>

以下代码示例演示了如何使用 `Import-EC2KeyPair`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将公钥导入到 EC2。第一行将公有密钥文件 (\$1.pub) 的内容存储在变量 `$publickey` 中。接下来，该示例将公钥文件的 UTF8 格式转换为 Base64 编码的字符串，并将转换后的字符串存储在变量中。`$pkbase64`在最后一行中，转换后的公钥被导入到 EC2。cmdlet 将密钥指纹和名称作为结果返回。**  

```
$publickey=[Io.File]::ReadAllText("C:\Users\TestUser\.ssh\id_rsa.pub")
$pkbase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($publickey))
Import-EC2KeyPair -KeyName Example-user-key -PublicKey $pkbase64
```
**输出**：  

```
KeyFingerprint                                  KeyName
--------------                                  -------
do:d0:15:8f:79:97:12:be:00:fd:df:31:z3:b1:42:z1 Example-user-key
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ImportKeyPair](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Import-EC2Snapshot`
<a name="ec2_ImportSnapshot_powershell_topic"></a>

以下代码示例演示了如何使用 `Import-EC2Snapshot`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将格式为“VMDK”的虚拟机磁盘映像导入到 Amazon EBS 快照中。该示例需要一个默认名称为 “vmimport” 的虚拟机导入服务角色，其策略允许亚马逊 EC2 访问指定的存储桶，如 http://docs.aws.amazon 中的`VM Import Prequisites`主题所述。 com/AWSEC2/latest/WindowsGuide/VMImportPrerequisites.html。要使用自定义角色，请使用 `-RoleName` 参数指定角色名称。**  

```
$parms = @{
    "ClientToken"="idempotencyToken"
    "Description"="Disk Image Import"
    "DiskContainer_Description" = "Data disk"
    "DiskContainer_Format" = "VMDK"
    "DiskContainer_S3Bucket" = "amzn-s3-demo-bucket"
    "DiskContainer_S3Key" = "datadiskimage.vmdk"
}

Import-EC2Snapshot @parms
```
**输出**：  

```
Description            ImportTaskId               SnapshotTaskDetail                                                          
-----------------      --------------------       ------------------                                                          
Disk Image Import      import-snap-abcdefgh       Amazon.EC2.Model.SnapshotTaskDetail
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ImportSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Move-EC2AddressToVpc`
<a name="ec2_MoveAddressToVpc_powershell_topic"></a>

以下代码示例演示了如何使用 `Move-EC2AddressToVpc`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将公有 IP 地址为 12.345.67.89 的 EC2 实例移动到美国东部（弗吉尼亚北部）区域的 EC2-VPC 平台。**  

```
Move-EC2AddressToVpc -PublicIp 12.345.67.89 -Region us-east-1
```
**示例 2：此示例将Get-EC2Instance命令的结果传送到 Move-EC2AddressToVpc cmdlet。该Get-EC2Instance命令获取由实例 ID 指定的实例，然后返回该实例的公有 IP 地址属性。**  

```
(Get-EC2Instance -Instance i-12345678).Instances.PublicIpAddress | Move-EC2AddressToVpc
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [MoveAddressToVpc](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Address`
<a name="ec2_AllocateAddress_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Address`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例分配一个弹性 IP 地址，供 VPC 中的实例使用。**  

```
New-EC2Address -Domain Vpc
```
**输出**：  

```
AllocationId         Domain      PublicIp
------------         ------      --------
eipalloc-12345678    vpc         198.51.100.2
```
**示例 2：此示例分配弹性 IP 地址以用于 EC2-Classic 中的实例。**  

```
New-EC2Address
```
**输出**：  

```
AllocationId         Domain      PublicIp
------------         ------      --------
                     standard    203.0.113.17
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AllocateAddress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2CustomerGateway`
<a name="ec2_CreateCustomerGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2CustomerGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建指定的客户网关。**  

```
New-EC2CustomerGateway -Type ipsec.1 -PublicIp 203.0.113.12 -BgpAsn 65534
```
**输出**：  

```
BgpAsn            : 65534
CustomerGatewayId : cgw-1a2b3c4d
IpAddress         : 203.0.113.12
State             : available
Tags              : {}
Type              : ipsec.1
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateCustomerGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2DhcpOption`
<a name="ec2_CreateDhcpOptions_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2DhcpOption`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建指定的 DHCP 选项集。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$options = @( @{Key="domain-name";Values=@("abc.local")}, @{Key="domain-name-servers";Values=@("10.0.0.101","10.0.0.102")})
New-EC2DhcpOption -DhcpConfiguration $options
```
**输出**：  

```
DhcpConfigurations                    DhcpOptionsId    Tags
------------------                    -------------    ----
{domain-name, domain-name-servers}    dopt-1a2b3c4d    {}
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建每个 DHCP 选项。**  

```
$option1 = New-Object Amazon.EC2.Model.DhcpConfiguration
$option1.Key = "domain-name"
$option1.Values = "abc.local"

$option2 = New-Object Amazon.EC2.Model.DhcpConfiguration
$option2.Key = "domain-name-servers"
$option2.Values = @("10.0.0.101","10.0.0.102")

New-EC2DhcpOption -DhcpConfiguration @($option1, $option2)
```
**输出**：  

```
DhcpConfigurations                    DhcpOptionsId    Tags
------------------                    -------------    ----
{domain-name, domain-name-servers}    dopt-2a3b4c5d    {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2FlowLog`
<a name="ec2_CreateFlowLogs_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2FlowLog`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用 “管理员” 角色的权限为所有 “拒绝” EC2 流量创建子网 subnet-1d234567 到 cloud-watch-log名为 “subnet1-log” 的流日志**  

```
New-EC2FlowLog -ResourceId "subnet-1d234567" -LogDestinationType cloud-watch-logs -LogGroupName subnet1-log -TrafficType "REJECT" -ResourceType Subnet -DeliverLogsPermissionArn "arn:aws:iam::98765432109:role/Admin"
```
**输出**：  

```
ClientToken                                  FlowLogIds             Unsuccessful
-----------                                  ----------             ------------
m1VN2cxP3iB4qo//VUKl5EU6cF7gQLOxcqNefvjeTGw= {fl-012fc34eed5678c9d} {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateFlowLogs](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Host`
<a name="ec2_AllocateHosts_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Host`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例向您的账户分配给定实例类型和可用区的专属主机**  

```
New-EC2Host -AutoPlacement on -AvailabilityZone eu-west-1b -InstanceType m4.xlarge -Quantity 1
```
**输出**：  

```
h-01e23f4cd567890f3
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AllocateHosts](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2HostReservation`
<a name="ec2_PurchaseHostReservation_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2HostReservation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例购买可提供 0c1f23456789d0ab 的预留，其配置与专属主机 h-01e23f4cd567890f1 的配置匹配**  

```
New-EC2HostReservation -OfferingId hro-0c1f23456789d0ab HostIdSet h-01e23f4cd567890f1
```
**输出**：  

```
ClientToken       :
CurrencyCode      :
Purchase          : {hr-0123f4b5d67bedc89}
TotalHourlyPrice  : 1.307
TotalUpfrontPrice : 0.000
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [PurchaseHostReservation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Image`
<a name="ec2_CreateImage_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Image`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的实例创建具有指定名称和描述的 AMI。Amazon EC2 尝试在创建映像之前彻底关闭实例，并在完成后重新启动实例。**  

```
New-EC2Image -InstanceId i-12345678 -Name "my-web-server" -Description "My web server AMI"
```
**示例 2：此示例从指定的实例创建具有指定名称和描述的 AMI。Amazon 在不关闭和重启实例的情况下 EC2 创建映像；因此，无法保证所创建映像的文件系统的完整性。**  

```
New-EC2Image -InstanceId i-12345678 -Name "my-web-server" -Description "My web server AMI" -NoReboot $true
```
**示例 3：此示例创建一个包含三个卷的 AMI。第一个卷基于 Amazon EBS 快照。第二个卷是一个空的 100 GiB Amazon EBS 卷。第三卷是一个实例存储卷。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ebsBlock1 = @{SnapshotId="snap-1a2b3c4d"}
$ebsBlock2 = @{VolumeSize=100}

New-EC2Image -InstanceId i-12345678 -Name "my-web-server" -Description "My web server AMI" -BlockDeviceMapping @( @{DeviceName="/dev/sdf";Ebs=$ebsBlock1}, @{DeviceName="/dev/sdg";Ebs=$ebsBlock2}, @{DeviceName="/dev/sdc";VirtualName="ephemeral0"})
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateImage](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Instance`
<a name="ec2_RunInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Instance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例在 EC2-Classic 或默认 VPC 中启动指定 AMI 的单个实例。**  

```
New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -InstanceType m3.medium -KeyName my-key-pair -SecurityGroup my-security-group
```
**示例 2：此示例在 VPC 中启动指定 AMI 的单个实例。**  

```
New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -SubnetId subnet-12345678 -InstanceType t2.micro -KeyName my-key-pair -SecurityGroupId sg-12345678
```
**示例 3：要添加 EBS 卷或实例存储卷，请定义块设备映射并将其添加到命令中。此示例添加实例存储卷。**  

```
$bdm = New-Object Amazon.EC2.Model.BlockDeviceMapping
$bdm.VirtualName = "ephemeral0"
$bdm.DeviceName = "/dev/sdf"

New-EC2Instance -ImageId ami-12345678 -BlockDeviceMapping $bdm ...
```
**示例 4：要指定当前 Windows 中的一个 AMIs，请使用 Get-I SSMLatest EC2 mage 获取其 AMI ID。此示例从适用于 Windows Server 2016 的当前基础 AMI 启动一个实例。**  

```
$ami = (Get-SSMLatestEC2Image -Path 'ami-windows-latest' -ImageName 'WINDOWS*2016*English*Core*BASE').Value

New-EC2Instance -ImageId $ami ...
```
**示例 5：将实例启动到指定的专属主机环境中。**  

```
New-EC2Instance -ImageId ami-1a2b3c4d -InstanceType m4.large -KeyName my-key-pair -SecurityGroupId sg-1a2b3c4d  -AvailabilityZone us-west-1a -Tenancy host -HostID h-1a2b3c4d5e6f1a2b3
```
**示例 6：此请求启动两个实例，并将键为 webserver 和值为 production 的标签应用于实例。该请求还向创建的卷（此示例中为每个实例的根卷）应用键为 cost-center 且值为 cc123 的标签。**  

```
$tag1 = @{ Key="webserver"; Value="production" }
$tag2 = @{ Key="cost-center"; Value="cc123" }

$tagspec1 = new-object Amazon.EC2.Model.TagSpecification
$tagspec1.ResourceType = "instance"
$tagspec1.Tags.Add($tag1)

$tagspec2 = new-object Amazon.EC2.Model.TagSpecification
$tagspec2.ResourceType = "volume"
$tagspec2.Tags.Add($tag2)

New-EC2Instance -ImageId "ami-1a2b3c4d" -KeyName "my-key-pair" -MaxCount 2 -InstanceType "t2.large" -SubnetId "subnet-1a2b3c4d" -TagSpecification $tagspec1,$tagspec2
```
**示例 7：此示例验证使用 DryRun 参数启动 EC2 实例的权限，而无需实际创建实例。注：这在操作成功时会引发异常，这是预期行为。**  

```
New-EC2Instance -ImageId 'ami-12345678' -InstanceType 't2.micro' -KeyName 'my-key-pair' -Region 'us-west-2' -DryRun $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RunInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2InstanceExportTask`
<a name="ec2_CreateInstanceExportTask_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2InstanceExportTask`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将已停止的实例 `i-0800b00a00EXAMPLE` 作为虚拟硬盘（VHD）导出到 S3 存储桶 `testbucket-export-instances-2019`。目标环境是`Microsoft`，添加区域参数是因为实例位于该区域，而用户的默认`us-east-1` AWS 区域不是 us-east-1。要获取导出任务的状态，请复制此命令的结果中的 `ExportTaskId` 值，然后运行 `Get-EC2ExportTask -ExportTaskId export_task_ID_from_results.`**  

```
New-EC2InstanceExportTask -InstanceId i-0800b00a00EXAMPLE -ExportToS3Task_DiskImageFormat VHD -ExportToS3Task_S3Bucket "amzn-s3-demo-bucket" -TargetEnvironment Microsoft -Region us-east-1
```
**输出**：  

```
Description           : 
ExportTaskId          : export-i-077c73108aEXAMPLE
ExportToS3Task        : Amazon.EC2.Model.ExportToS3Task
InstanceExportDetails : Amazon.EC2.Model.InstanceExportDetails
State                 : active
StatusMessage         :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateInstanceExportTask](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2InternetGateway`
<a name="ec2_CreateInternetGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2InternetGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建互联网网关。**  

```
New-EC2InternetGateway
```
**输出**：  

```
Attachments    InternetGatewayId    Tags
-----------    -----------------    ----
{}             igw-1a2b3c4d         {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2KeyPair`
<a name="ec2_CreateKeyPair_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2KeyPair`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建一个密钥对，并在具有指定名称的文件中捕获经过 PEM 编码的 RSA 私有密钥。使用时 PowerShell，必须将编码设置为 ascii 才能生成有效的密钥。有关更多信息，请参阅《 AWS 命令行界面用户指南》中的创建、显示和删除亚马逊 EC2 密钥对 (https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-keypairs.html)。**  

```
(New-EC2KeyPair -KeyName "my-key-pair").KeyMaterial | Out-File -Encoding ascii -FilePath C:\path\my-key-pair.pem
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateKeyPair](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2NetworkAcl`
<a name="ec2_CreateNetworkAcl_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2NetworkAcl`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的 VPC 创建网络 ACL。**  

```
New-EC2NetworkAcl -VpcId vpc-12345678
```
**输出**：  

```
Associations : {}
Entries      : {Amazon.EC2.Model.NetworkAclEntry, Amazon.EC2.Model.NetworkAclEntry}
IsDefault    : False
NetworkAclId : acl-12345678
Tags         : {}
VpcId        : vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateNetworkAcl](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2NetworkAclEntry`
<a name="ec2_CreateNetworkAclEntry_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2NetworkAclEntry`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的网络 ACL 创建一个条目。该规则可让来自 UDP 端口 53（DNS）上任何地址（0.0.0.0/0）的入站流量进入任何关联的子网。**  

```
New-EC2NetworkAclEntry -NetworkAclId acl-12345678 -Egress $false -RuleNumber 100 -Protocol 17 -PortRange_From 53 -PortRange_To 53 -CidrBlock 0.0.0.0/0 -RuleAction allow
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateNetworkAclEntry](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2NetworkInterface`
<a name="ec2_CreateNetworkInterface_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2NetworkInterface`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建指定的网络接口。**  

```
New-EC2NetworkInterface -SubnetId subnet-1a2b3c4d -Description "my network interface" -Group sg-12345678 -PrivateIpAddress 10.0.0.17
```
**输出**：  

```
Association        :
Attachment         :
AvailabilityZone   : us-west-2c
Description        : my network interface
Groups             : {my-security-group}
MacAddress         : 0a:72:bc:1a:cd:7f
NetworkInterfaceId : eni-12345678
OwnerId            : 123456789012
PrivateDnsName     : ip-10-0-0-17.us-west-2.compute.internal
PrivateIpAddress   : 10.0.0.17
PrivateIpAddresses : {}
RequesterId        :
RequesterManaged   : False
SourceDestCheck    : True
Status             : pending
SubnetId           : subnet-1a2b3c4d
TagSet             : {}
VpcId              : vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2PlacementGroup`
<a name="ec2_CreatePlacementGroup_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2PlacementGroup`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例命令使用指定的名称创建置放群组。**  

```
New-EC2PlacementGroup -GroupName my-placement-group -Strategy cluster
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreatePlacementGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Route`
<a name="ec2_CreateRoute_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Route`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的路由表创建指定的路由。该路由匹配所有流量，并将其路由到指定的互联网网关。**  

```
New-EC2Route -RouteTableId rtb-1a2b3c4d -DestinationCidrBlock 0.0.0.0/0 -GatewayId igw-1a2b3c4d
```
**输出**：  

```
True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateRoute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2RouteTable`
<a name="ec2_CreateRouteTable_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2RouteTable`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的 VPC 创建路由表。**  

```
New-EC2RouteTable -VpcId vpc-12345678
```
**输出**：  

```
Associations    : {}
PropagatingVgws : {}
Routes          : {}
RouteTableId    : rtb-1a2b3c4d
Tags            : {}
VpcId           : vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2ScheduledInstance`
<a name="ec2_RunScheduledInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2ScheduledInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启动指定的计划实例。**  

```
New-EC2ScheduledInstance -ScheduledInstanceId sci-1234-1234-1234-1234-123456789012 -InstanceCount 1 `
-IamInstanceProfile_Name my-iam-role `
-LaunchSpecification_ImageId ami-12345678 `
-LaunchSpecification_InstanceType c4.large `
-LaunchSpecification_SubnetId subnet-12345678`
-LaunchSpecification_SecurityGroupId sg-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RunScheduledInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2ScheduledInstancePurchase`
<a name="ec2_PurchaseScheduledInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2ScheduledInstancePurchase`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例购买计划实例。**  

```
$request = New-Object Amazon.EC2.Model.PurchaseRequest
$request.InstanceCount = 1
$request.PurchaseToken = "eyJ2IjoiMSIsInMiOjEsImMiOi..."
New-EC2ScheduledInstancePurchase -PurchaseRequest $request
```
**输出**：  

```
AvailabilityZone            : us-west-2b
CreateDate                  : 1/25/2016 1:43:38 PM
HourlyPrice                 : 0.095
InstanceCount               : 1
InstanceType                : c4.large
NetworkPlatform             : EC2-VPC
NextSlotStartTime           : 1/31/2016 1:00:00 AM
Platform                    : Linux/UNIX
PreviousSlotEndTime         : 
Recurrence                  : Amazon.EC2.Model.ScheduledInstanceRecurrence
ScheduledInstanceId         : sci-1234-1234-1234-1234-123456789012
SlotDurationInHours         : 32
TermEndDate                 : 1/31/2017 1:00:00 AM
TermStartDate               : 1/31/2016 1:00:00 AM
TotalScheduledInstanceHours : 1696
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [PurchaseScheduledInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2SecurityGroup`
<a name="ec2_CreateSecurityGroup_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2SecurityGroup`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的 VPC 创建一个安全组。**  

```
New-EC2SecurityGroup -GroupName my-security-group -Description "my security group" -VpcId vpc-12345678
```
**输出**：  

```
sg-12345678
```
**示例 2：此示例为 EC2-Classic 创建了一个安全组。**  

```
New-EC2SecurityGroup -GroupName my-security-group -Description "my security group"
```
**输出**：  

```
sg-45678901
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateSecurityGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Snapshot`
<a name="ec2_CreateSnapshot_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Snapshot`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建指定卷的快照。**  

```
New-EC2Snapshot -VolumeId vol-12345678 -Description "This is a test"
```
**输出**：  

```
DataEncryptionKeyId :
Description         : This is a test
Encrypted           : False
KmsKeyId            :
OwnerAlias          :
OwnerId             : 123456789012
Progress            :
SnapshotId          : snap-12345678
StartTime           : 12/22/2015 1:28:42 AM
State               : pending
StateMessage        :
Tags                : {}
VolumeId            : vol-12345678
VolumeSize          : 20
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2SpotDatafeedSubscription`
<a name="ec2_CreateSpotDatafeedSubscription_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2SpotDatafeedSubscription`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建竞价型实例数据源。**  

```
New-EC2SpotDatafeedSubscription -Bucket amzn-s3-demo-bucket -Prefix spotdata
```
**输出**：  

```
Bucket  : amzn-s3-demo-bucket
Fault   :
OwnerId : 123456789012
Prefix  : spotdata
State   : Active
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Subnet`
<a name="ec2_CreateSubnet_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Subnet`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用指定的 CIDR 创建子网。**  

```
New-EC2Subnet -VpcId vpc-12345678 -CidrBlock 10.0.0.0/24
```
**输出**：  

```
AvailabilityZone        : us-west-2c
AvailableIpAddressCount : 251
CidrBlock               : 10.0.0.0/24
DefaultForAz            : False
MapPublicIpOnLaunch     : False
State                   : pending
SubnetId                : subnet-1a2b3c4d
Tag                     : {}
VpcId                   : vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateSubnet](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Tag`
<a name="ec2_CreateTags_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Tag`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例向指定的资源添加单个标签。标签键为 “myTag”，标签值为 “myTagValue”。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
New-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag"; Value="myTagValue" }
```
**示例 2：此示例更新指定的标签，或将其添加到指定的资源。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
New-EC2Tag -Resource i-12345678 -Tag @( @{ Key="myTag"; Value="newTagValue" }, @{ Key="test"; Value="anotherTagValue" } )
```
**示例 3：在 PowerShell 版本 2 中，必须使用 New-Object 为标签参数创建标签。**  

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

New-EC2Tag -Resource i-12345678 -Tag $tag
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateTags](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Volume`
<a name="ec2_CreateVolume_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Volume`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建指定的卷。**  

```
New-EC2Volume -Size 50 -AvailabilityZone us-west-2a -VolumeType gp2
```
**输出**：  

```
Attachments      : {}
AvailabilityZone : us-west-2a
CreateTime       : 12/22/2015 1:42:07 AM
Encrypted        : False
Iops             : 150
KmsKeyId         :
Size             : 50
SnapshotId       :
State            : creating
Tags             : {}
VolumeId         : vol-12345678
VolumeType       : gp2
```
**示例 2：此示例请求创建一个卷，并应用键为 stack 且值为 production 的标签。**  

```
$tag = @{ Key="stack"; Value="production" }

$tagspec = new-object Amazon.EC2.Model.TagSpecification
$tagspec.ResourceType = "volume"
$tagspec.Tags.Add($tag)

New-EC2Volume -Size 80 -AvailabilityZone "us-west-2a" -TagSpecification $tagspec
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateVolume](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2Vpc`
<a name="ec2_CreateVpc_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2Vpc`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用指定的 CIDR 创建 VPC。Amazon VPC 还会为 VPC 创建以下各项：默认 DHCP 选项集、主路由表和默认网络 ACL。**  

```
New-EC2VPC -CidrBlock 10.0.0.0/16
```
**输出**：  

```
CidrBlock       : 10.0.0.0/16
DhcpOptionsId   : dopt-1a2b3c4d
InstanceTenancy : default
IsDefault       : False
State           : pending
Tags            : {}
VpcId           : vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateVpc](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2VpcEndpoint`
<a name="ec2_CreateVpcEndpoint_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2VpcEndpoint`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例在 VPC vpc-0fc1ff23f45b678eb 中为服务 com.amazonaws.eu-west-1.s3 创建新的 VPC 端点**  

```
New-EC2VpcEndpoint -ServiceName com.amazonaws.eu-west-1.s3 -VpcId vpc-0fc1ff23f45b678eb
```
**输出**：  

```
ClientToken VpcEndpoint
----------- -----------
            Amazon.EC2.Model.VpcEndpoint
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateVpcEndpoint](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2VpnConnection`
<a name="ec2_CreateVpnConnection_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2VpnConnection`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例在指定的虚拟专用网关和指定的客户网关之间创建 VPN 连接。输出包括网络管理员需要的配置信息（采用 XML 格式）。**  

```
New-EC2VpnConnection -Type ipsec.1 -CustomerGatewayId cgw-1a2b3c4d -VpnGatewayId vgw-1a2b3c4d
```
**输出**：  

```
CustomerGatewayConfiguration : [XML document]
CustomerGatewayId            : cgw-1a2b3c4d
Options                      :
Routes                       : {}
State                        : pending
Tags                         : {}
Type                         :
VgwTelemetry                 : {}
VpnConnectionId              : vpn-12345678
VpnGatewayId                 : vgw-1a2b3c4d
```
**示例 2：此示例创建 VPN 连接，并在具有指定名称的文件中捕获配置。**  

```
(New-EC2VpnConnection -CustomerGatewayId cgw-1a2b3c4d -VpnGatewayId vgw-1a2b3c4d).CustomerGatewayConfiguration | Out-File C:\path\vpn-configuration.xml
```
**示例 3：此示例在指定的虚拟专用网关和指定的客户网关之间创建 VPN 连接以及静态路由。**  

```
New-EC2VpnConnection -Type ipsec.1 -CustomerGatewayId cgw-1a2b3c4d -VpnGatewayId vgw-1a2b3c4d -Options_StaticRoutesOnly $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateVpnConnection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2VpnConnectionRoute`
<a name="ec2_CreateVpnConnectionRoute_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2VpnConnectionRoute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为指定的 VPN 连接创建指定的静态路由。**  

```
New-EC2VpnConnectionRoute -VpnConnectionId vpn-12345678 -DestinationCidrBlock 11.12.0.0/16
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateVpnConnectionRoute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EC2VpnGateway`
<a name="ec2_CreateVpnGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `New-EC2VpnGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建指定的虚拟专用网关。**  

```
New-EC2VpnGateway -Type ipsec.1
```
**输出**：  

```
AvailabilityZone :
State            : available
Tags             : {}
Type             : ipsec.1
VpcAttachments   : {}
VpnGatewayId     : vgw-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Register-EC2Address`
<a name="ec2_AssociateAddress_powershell_topic"></a>

以下代码示例演示了如何使用 `Register-EC2Address`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的弹性 IP 地址与 VPC 中的指定实例相关联。**  

```
C:\> Register-EC2Address -InstanceId i-12345678 -AllocationId eipalloc-12345678
```
**输出**：  

```
eipassoc-12345678
```
**示例 2：此示例将指定的弹性 IP 地址与 EC2-Classic 中的指定实例相关联。**  

```
C:\> Register-EC2Address -InstanceId i-12345678 -PublicIp 203.0.113.17
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AssociateAddress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Register-EC2DhcpOption`
<a name="ec2_AssociateDhcpOptions_powershell_topic"></a>

以下代码示例演示了如何使用 `Register-EC2DhcpOption`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的 DHCP 选项集与指定的 VPC 相关联。**  

```
Register-EC2DhcpOption -DhcpOptionsId dopt-1a2b3c4d -VpcId vpc-12345678
```
**示例 2：此示例将默认 DHCP 选项集与指定的 VPC 相关联。**  

```
Register-EC2DhcpOption -DhcpOptionsId default -VpcId vpc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AssociateDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Register-EC2Image`
<a name="ec2_RegisterImage_powershell_topic"></a>

以下代码示例演示了如何使用 `Register-EC2Image`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例在 Amazon S3 中使用指定的清单文件注册 AMI。**  

```
Register-EC2Image -ImageLocation amzn-s3-demo-bucket/my-web-server-ami/image.manifest.xml -Name my-web-server-ami
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RegisterImage](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Register-EC2PrivateIpAddress`
<a name="ec2_AssignPrivateIpAddresses_powershell_topic"></a>

以下代码示例演示了如何使用 `Register-EC2PrivateIpAddress`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的辅助私有 IP 地址分配给指定的网络接口。**  

```
Register-EC2PrivateIpAddress -NetworkInterfaceId eni-1a2b3c4d -PrivateIpAddress 10.0.0.82
```
**示例 2：此示例创建两个辅助私有 IP 地址并将它们分配给指定的网络接口。**  

```
Register-EC2PrivateIpAddress -NetworkInterfaceId eni-1a2b3c4d -SecondaryPrivateIpAddressCount 2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AssignPrivateIpAddresses](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Register-EC2RouteTable`
<a name="ec2_AssociateRouteTable_powershell_topic"></a>

以下代码示例演示了如何使用 `Register-EC2RouteTable`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的路由表与指定的子网相关联。**  

```
Register-EC2RouteTable -RouteTableId rtb-1a2b3c4d -SubnetId subnet-1a2b3c4d
```
**输出**：  

```
rtbassoc-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AssociateRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Address`
<a name="ec2_ReleaseAddress_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Address`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例为 VPC 中的实例释放指定的弹性 IP 地址。**  

```
Remove-EC2Address -AllocationId eipalloc-12345678 -Force
```
**示例 2：此示例为 EC2-Classic 中的实例释放指定的弹性 IP 地址。**  

```
Remove-EC2Address -PublicIp 198.51.100.2 -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReleaseAddress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2CapacityReservation`
<a name="ec2_CancelCapacityReservation_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2CapacityReservation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例取消容量预留 cr-0c1f2345db6f7cdba**  

```
Remove-EC2CapacityReservation -CapacityReservationId cr-0c1f2345db6f7cdba
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2CapacityReservation (CancelCapacityReservation)" on target "cr-0c1f2345db6f7cdba".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CancelCapacityReservation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2CustomerGateway`
<a name="ec2_DeleteCustomerGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2CustomerGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的客户网关。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2CustomerGateway -CustomerGatewayId cgw-1a2b3c4d
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2CustomerGateway (DeleteCustomerGateway)" on Target "cgw-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteCustomerGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2DhcpOption`
<a name="ec2_DeleteDhcpOptions_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2DhcpOption`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的 DHCP 选项集。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2DhcpOption -DhcpOptionsId dopt-1a2b3c4d
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2DhcpOption (DeleteDhcpOptions)" on Target "dopt-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2FlowLog`
<a name="ec2_DeleteFlowLogs_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2FlowLog`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除了给定的 FlowLogId fl-01a2b3456a789c01**  

```
Remove-EC2FlowLog -FlowLogId fl-01a2b3456a789c01
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2FlowLog (DeleteFlowLogs)" on target "fl-01a2b3456a789c01".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteFlowLogs](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Host`
<a name="ec2_ReleaseHosts_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Host`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例释放给定的主机 ID 0badafd1dcb2f3456**  

```
Remove-EC2Host -HostId h-0badafd1dcb2f3456
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2Host (ReleaseHosts)" on target "h-0badafd1dcb2f3456".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Successful            Unsuccessful
----------            ------------
{h-0badafd1dcb2f3456} {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReleaseHosts](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Instance`
<a name="ec2_TerminateInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Instance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例终止指定的实例（该实例可能正在运行或处于“已停止”状态）。在继续操作之前，cmdlet 会提示您进行确认；使用 -Force 开关可禁止提示。**  

```
Remove-EC2Instance -InstanceId i-12345678
```
**输出**：  

```
CurrentState                      InstanceId    PreviousState
------------                      ----------    -------------
Amazon.EC2.Model.InstanceState    i-12345678    Amazon.EC2.Model.InstanceState
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [TerminateInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2InternetGateway`
<a name="ec2_DeleteInternetGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2InternetGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的互联网网关。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2InternetGateway (DeleteInternetGateway)" on Target "igw-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2KeyPair`
<a name="ec2_DeleteKeyPair_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2KeyPair`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的密钥对。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2KeyPair -KeyName my-key-pair
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2KeyPair (DeleteKeyPair)" on Target "my-key-pair".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteKeyPair](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2NetworkAcl`
<a name="ec2_DeleteNetworkAcl_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2NetworkAcl`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的网络 ACL。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2NetworkAcl -NetworkAclId acl-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2NetworkAcl (DeleteNetworkAcl)" on Target "acl-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteNetworkAcl](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2NetworkAclEntry`
<a name="ec2_DeleteNetworkAclEntry_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2NetworkAclEntry`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的网络 ACL 移除指定的规则。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2NetworkAclEntry -NetworkAclId acl-12345678 -Egress $false -RuleNumber 100
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2NetworkAclEntry (DeleteNetworkAclEntry)" on Target "acl-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteNetworkAclEntry](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2NetworkInterface`
<a name="ec2_DeleteNetworkInterface_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2NetworkInterface`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的网络接口。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2NetworkInterface -NetworkInterfaceId eni-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2NetworkInterface (DeleteNetworkInterface)" on Target "eni-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2PlacementGroup`
<a name="ec2_DeletePlacementGroup_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2PlacementGroup`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的置放群组。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2PlacementGroup -GroupName my-placement-group
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2PlacementGroup (DeletePlacementGroup)" on Target "my-placement-group".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeletePlacementGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Route`
<a name="ec2_DeleteRoute_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Route`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的路由表中删除指定的路由。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2Route -RouteTableId rtb-1a2b3c4d -DestinationCidrBlock 0.0.0.0/0
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2Route (DeleteRoute)" on Target "rtb-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteRoute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2RouteTable`
<a name="ec2_DeleteRouteTable_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2RouteTable`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的路由表。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2RouteTable -RouteTableId rtb-1a2b3c4d
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2RouteTable (DeleteRouteTable)" on Target "rtb-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2SecurityGroup`
<a name="ec2_DeleteSecurityGroup_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2SecurityGroup`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除了 EC2-VPC 的指定安全组。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2SecurityGroup -GroupId sg-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2SecurityGroup (DeleteSecurityGroup)" on Target "sg-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**示例 2：此示例删除了 EC2-Classic 的指定安全组。**  

```
Remove-EC2SecurityGroup -GroupName my-security-group -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteSecurityGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Snapshot`
<a name="ec2_DeleteSnapshot_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Snapshot`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的快照。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2Snapshot -SnapshotId snap-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2Snapshot (DeleteSnapshot)" on target "snap-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2SpotDatafeedSubscription`
<a name="ec2_DeleteSpotDatafeedSubscription_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2SpotDatafeedSubscription`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除竞价型实例数据源。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2SpotDatafeedSubscription
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2SpotDatafeedSubscription (DeleteSpotDatafeedSubscription)" on Target "".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Subnet`
<a name="ec2_DeleteSubnet_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Subnet`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的子网。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2Subnet -SubnetId subnet-1a2b3c4d
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2Subnet (DeleteSubnet)" on Target "subnet-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteSubnet](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Tag`
<a name="ec2_DeleteTags_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Tag`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的资源删除指定的标签，无论标签值如何。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
Remove-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag" } -Force
```
**示例 2：此示例从指定的资源删除指定的标签，但前提是标签值匹配。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
Remove-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag";Value="myTagValue" } -Force
```
**示例 3：此示例从指定的资源删除指定的标签，无论标签值如何。**  

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

Remove-EC2Tag -Resource i-12345678 -Tag $tag -Force
```
**示例 4：此示例从指定的资源删除指定的标签，但前提是标签值匹配。**  

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

Remove-EC2Tag -Resource i-12345678 -Tag $tag -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteTags](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Volume`
<a name="ec2_DeleteVolume_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Volume`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例分离指定的卷。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2Volume -VolumeId vol-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2Volume (DeleteVolume)" on target "vol-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteVolume](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2Vpc`
<a name="ec2_DeleteVpc_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2Vpc`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的 VPC。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2Vpc -VpcId vpc-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2Vpc (DeleteVpc)" on Target "vpc-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteVpc](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2VpnConnection`
<a name="ec2_DeleteVpnConnection_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2VpnConnection`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的 VPN 连接。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2VpnConnection -VpnConnectionId vpn-12345678
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2VpnConnection (DeleteVpnConnection)" on Target "vpn-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteVpnConnection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2VpnConnectionRoute`
<a name="ec2_DeleteVpnConnectionRoute_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2VpnConnectionRoute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的 VPN 连接中移除指定的静态路由。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2VpnConnectionRoute -VpnConnectionId vpn-12345678 -DestinationCidrBlock 11.12.0.0/16
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2VpnConnectionRoute (DeleteVpnConnectionRoute)" on Target "vpn-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteVpnConnectionRoute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EC2VpnGateway`
<a name="ec2_DeleteVpnGateway_powershell_topic"></a>

以下代码示例演示了如何使用 `Remove-EC2VpnGateway`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定的虚拟专用网关。除非您还指定了 Force 参数，否则在操作继续之前，系统会提示您进行确认。**  

```
Remove-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d
```
**输出**：  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-EC2VpnGateway (DeleteVpnGateway)" on Target "vgw-1a2b3c4d".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Request-EC2SpotFleet`
<a name="ec2_RequestSpotFleet_powershell_topic"></a>

以下代码示例演示了如何使用 `Request-EC2SpotFleet`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例在价格最低的可用区中为指定的实例类型创建竞价型实例集请求。如果您的账户仅支持 EC2-VPC，则竞价型队列会在具有默认子网的价格最低的可用区启动实例。如果您的账户支持 EC2-Classic，则竞价型队列会在价格最低的可用区中启动 EC2-Classic 中的实例。请注意，您支付的价格不会超过请求的指定竞价价格。**  

```
$sg = New-Object Amazon.EC2.Model.GroupIdentifier
$sg.GroupId = "sg-12345678"
$lc = New-Object Amazon.EC2.Model.SpotFleetLaunchSpecification
$lc.ImageId = "ami-12345678"
$lc.InstanceType = "m3.medium"
$lc.SecurityGroups.Add($sg) 
Request-EC2SpotFleet -SpotFleetRequestConfig_SpotPrice 0.04 `
-SpotFleetRequestConfig_TargetCapacity 2 `
-SpotFleetRequestConfig_IamFleetRole arn:aws:iam::123456789012:role/my-spot-fleet-role `
-SpotFleetRequestConfig_LaunchSpecification $lc
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RequestSpotFleet](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Request-EC2SpotInstance`
<a name="ec2_RequestSpotInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Request-EC2SpotInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例在指定的子网中请求一次性竞价型实例。请注意，必须为包含指定子网的 VPC 创建安全组，并且必须使用网络接口通过 ID 指定该安全组。指定网络接口时，您必须包括使用网络接口的子网 ID。**  

```
$n = New-Object Amazon.EC2.Model.InstanceNetworkInterfaceSpecification
$n.DeviceIndex = 0
$n.SubnetId = "subnet-12345678"
$n.Groups.Add("sg-12345678")
Request-EC2SpotInstance -InstanceCount 1 -SpotPrice 0.050 -Type one-time `
-IamInstanceProfile_Arn arn:aws:iam::123456789012:instance-profile/my-iam-role `
-LaunchSpecification_ImageId ami-12345678 `
-LaunchSpecification_InstanceType m3.medium `
-LaunchSpecification_NetworkInterface $n
```
**输出**：  

```
ActualBlockHourlyPrice   :
AvailabilityZoneGroup    :
BlockDurationMinutes     : 0
CreateTime               : 12/26/2015 7:44:10 AM
Fault                    :
InstanceId               :
LaunchedAvailabilityZone :
LaunchGroup              :
LaunchSpecification      : Amazon.EC2.Model.LaunchSpecification
ProductDescription       : Linux/UNIX
SpotInstanceRequestId    : sir-12345678
SpotPrice                : 0.050000
State                    : open
Status                   : Amazon.EC2.Model.SpotInstanceStatus
Tags                     : {}
Type                     : one-time
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RequestSpotInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Reset-EC2ImageAttribute`
<a name="ec2_ResetImageAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Reset-EC2ImageAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将“launchPermission”属性重置为其默认值。默认情况下， AMIs 是私有的。**  

```
Reset-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ResetImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Reset-EC2InstanceAttribute`
<a name="ec2_ResetInstanceAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Reset-EC2InstanceAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例重置指定实例sriovNetSupport的 “” 属性。**  

```
Reset-EC2InstanceAttribute -InstanceId i-12345678 -Attribute sriovNetSupport
```
**示例 2：此示例重置指定实例的“ebsOptimized”属性。**  

```
Reset-EC2InstanceAttribute -InstanceId i-12345678 -Attribute ebsOptimized
```
**示例 3：此示例重置指定实例sourceDestCheck的 “” 属性。**  

```
Reset-EC2InstanceAttribute -InstanceId i-12345678 -Attribute sourceDestCheck
```
**示例 4：此示例重置指定实例disableApiTermination的 “” 属性。**  

```
Reset-EC2InstanceAttribute -InstanceId i-12345678 -Attribute disableApiTermination
```
**示例 5：此示例重置指定实例的 instanceInitiatedShutdown “行为” 属性。**  

```
Reset-EC2InstanceAttribute -InstanceId i-12345678 -Attribute instanceInitiatedShutdownBehavior
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ResetInstanceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Reset-EC2NetworkInterfaceAttribute`
<a name="ec2_ResetNetworkInterfaceAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Reset-EC2NetworkInterfaceAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例重置对指定网络接口的 source/destination 检查。**  

```
Reset-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -SourceDestCheck
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ResetNetworkInterfaceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Reset-EC2SnapshotAttribute`
<a name="ec2_ResetSnapshotAttribute_powershell_topic"></a>

以下代码示例演示了如何使用 `Reset-EC2SnapshotAttribute`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例重置指定快照的指定属性。**  

```
Reset-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute CreateVolumePermission
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ResetSnapshotAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Restart-EC2Instance`
<a name="ec2_RebootInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Restart-EC2Instance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例重启指定的实例。**  

```
Restart-EC2Instance -InstanceId i-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RebootInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Revoke-EC2SecurityGroupEgress`
<a name="ec2_RevokeSecurityGroupEgress_powershell_topic"></a>

以下代码示例演示了如何使用 `Revoke-EC2SecurityGroupEgress`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除了指定安全组的 EC2-VPC 规则。这将撤销对 TCP 端口 80 上指定 IP 地址范围的访问权限。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ip = @{ IpProtocol="tcp"; FromPort="80"; ToPort="80"; IpRanges="203.0.113.0/24" }
Revoke-EC2SecurityGroupEgress -GroupId sg-12345678 -IpPermission $ip
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建对象。 IpPermission **  

```
$ip = New-Object Amazon.EC2.Model.IpPermission
$ip.IpProtocol = "tcp"
$ip.FromPort = 80
$ip.ToPort = 80
$ip.IpRanges.Add("203.0.113.0/24")
Revoke-EC2SecurityGroupEgress -GroupId sg-12345678 -IpPermission $ip
```
**示例 3：此示例撤销对 TCP 端口 80 上指定源安全组的访问权限。**  

```
$ug = New-Object Amazon.EC2.Model.UserIdGroupPair
$ug.GroupId = "sg-1a2b3c4d"
$ug.UserId = "123456789012"
Revoke-EC2SecurityGroupEgress -GroupId sg-12345678 -IpPermission @( @{ IpProtocol="tcp"; FromPort="80"; ToPort="80"; UserIdGroupPairs=$ug } )
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RevokeSecurityGroupEgress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Revoke-EC2SecurityGroupIngress`
<a name="ec2_RevokeSecurityGroupIngress_powershell_topic"></a>

以下代码示例演示了如何使用 `Revoke-EC2SecurityGroupIngress`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例撤消了 EC2-VPC 的指定安全组的指定地址范围内对 TCP 端口 22 的访问权限。请注意，您必须使用安全组 ID 而不是安全组名称来识别 EC2-VPC 的安全组。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ip = @{ IpProtocol="tcp"; FromPort="22"; ToPort="22"; IpRanges="203.0.113.0/24" }
Revoke-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission $ip
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建对象。 IpPermission **  

```
$ip = New-Object Amazon.EC2.Model.IpPermission
$ip.IpProtocol = "tcp"
$ip.FromPort = 22
$ip.ToPort = 22
$ip.IpRanges.Add("203.0.113.0/24")

Revoke-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission $ip
```
**示例 3：此示例撤消了 EC2-Classic 的指定安全组的指定地址范围内对 TCP 端口 22 的访问权限。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$ip = @{ IpProtocol="tcp"; FromPort="22"; ToPort="22"; IpRanges="203.0.113.0/24" }

Revoke-EC2SecurityGroupIngress -GroupName "my-security-group" -IpPermission $ip
```
**示例 4：在 PowerShell 版本 2 中，必须使用 New-Object 来创建对象。 IpPermission **  

```
$ip = New-Object Amazon.EC2.Model.IpPermission
$ip.IpProtocol = "tcp"
$ip.FromPort = 22
$ip.ToPort = 22
$ip.IpRanges.Add("203.0.113.0/24")

Revoke-EC2SecurityGroupIngress -GroupName "my-security-group" -IpPermission $ip
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RevokeSecurityGroupIngress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Send-EC2InstanceStatus`
<a name="ec2_ReportInstanceStatus_powershell_topic"></a>

以下代码示例演示了如何使用 `Send-EC2InstanceStatus`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例报告指定实例的状态反馈。**  

```
Send-EC2InstanceStatus -Instance i-12345678 -Status impaired -ReasonCode unresponsive
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReportInstanceStatus](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Set-EC2NetworkAclAssociation`
<a name="ec2_ReplaceNetworkAclAssociation_powershell_topic"></a>

以下代码示例演示了如何使用 `Set-EC2NetworkAclAssociation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的网络 ACL 与指定网络 ACL 关联的子网相关联。**  

```
Set-EC2NetworkAclAssociation -NetworkAclId acl-12345678 -AssociationId aclassoc-1a2b3c4d
```
**输出**：  

```
aclassoc-87654321
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReplaceNetworkAclAssociation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Set-EC2NetworkAclEntry`
<a name="ec2_ReplaceNetworkAclEntry_powershell_topic"></a>

以下代码示例演示了如何使用 `Set-EC2NetworkAclEntry`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例替换指定网络 ACL 的指定条目。新规则支持从指定地址到任何关联子网的入站流量。**  

```
Set-EC2NetworkAclEntry -NetworkAclId acl-12345678 -Egress $false -RuleNumber 100 -Protocol 17 -PortRange_From 53 -PortRange_To 53 -CidrBlock 203.0.113.12/24 -RuleAction allow
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReplaceNetworkAclEntry](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Set-EC2Route`
<a name="ec2_ReplaceRoute_powershell_topic"></a>

以下代码示例演示了如何使用 `Set-EC2Route`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例替换指定路由表的指定路由。新路由将指定的流量发送到指定的虚拟专用网关。**  

```
Set-EC2Route -RouteTableId rtb-1a2b3c4d -DestinationCidrBlock 10.0.0.0/24 -GatewayId vgw-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReplaceRoute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Set-EC2RouteTableAssociation`
<a name="ec2_ReplaceRouteTableAssociation_powershell_topic"></a>

以下代码示例演示了如何使用 `Set-EC2RouteTableAssociation`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的路由表与指定路由表关联的子网相关联。**  

```
Set-EC2RouteTableAssociation -RouteTableId rtb-1a2b3c4d -AssociationId rtbassoc-12345678
```
**输出**：  

```
rtbassoc-87654321
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ReplaceRouteTableAssociation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Start-EC2Instance`
<a name="ec2_StartInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Start-EC2Instance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启动指定的实例。**  

```
Start-EC2Instance -InstanceId i-12345678
```
**输出**：  

```
CurrentState                      InstanceId    PreviousState
------------                      ----------    -------------
Amazon.EC2.Model.InstanceState    i-12345678    Amazon.EC2.Model.InstanceState
```
**示例 2：此示例启动指定的实例。**  

```
@("i-12345678", "i-76543210") | Start-EC2Instance
```
**示例 3：此示例启动当前已停止的一组实例。返回的实例对象通过Get-EC2Instance管道传送到。Start-EC2Instance此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
(Get-EC2Instance -Filter @{ Name="instance-state-name"; Values="stopped"}).Instances | Start-EC2Instance
```
**示例 4：在 PowerShell 版本 2 中，必须使用 New-Object 为 Filter 参数创建过滤器。**  

```
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = "instance-state-name"
$filter.Values = "stopped"

(Get-EC2Instance -Filter $filter).Instances | Start-EC2Instance
```
**示例 5：此示例验证了在不实际启动 EC2 实例的情况下使用 DryRun 参数启动实例的权限。注：这在操作成功时会引发异常，这是预期行为。**  

```
Start-EC2Instance -InstanceId 'i-0abcdef123456' -Region 'us-west-1' -DryRun $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [StartInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Start-EC2InstanceMonitoring`
<a name="ec2_MonitorInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Start-EC2InstanceMonitoring`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启用对指定实例的详细监控。**  

```
Start-EC2InstanceMonitoring -InstanceId i-12345678
```
**输出**：  

```
InstanceId    Monitoring
----------    ----------
i-12345678    Amazon.EC2.Model.Monitoring
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [MonitorInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Stop-EC2ImportTask`
<a name="ec2_CancelImportTask_powershell_topic"></a>

以下代码示例演示了如何使用 `Stop-EC2ImportTask`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例取消指定的导入任务（快照或映像导入）。如果需要，可以使用 `-CancelReason` 参数提供原因。**  

```
Stop-EC2ImportTask -ImportTaskId import-ami-abcdefgh
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CancelImportTask](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Stop-EC2Instance`
<a name="ec2_StopInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Stop-EC2Instance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例停止指定的实例。**  

```
Stop-EC2Instance -InstanceId i-12345678
```
**输出**：  

```
CurrentState                      InstanceId    PreviousState
------------                      ----------    -------------
Amazon.EC2.Model.InstanceState    i-12345678    Amazon.EC2.Model.InstanceState
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [StopInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Stop-EC2InstanceMonitoring`
<a name="ec2_UnmonitorInstances_powershell_topic"></a>

以下代码示例演示了如何使用 `Stop-EC2InstanceMonitoring`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例禁用对指定实例的详细监控。**  

```
Stop-EC2InstanceMonitoring -InstanceId i-12345678
```
**输出**：  

```
InstanceId    Monitoring
----------    ----------
i-12345678    Amazon.EC2.Model.Monitoring
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UnmonitorInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Stop-EC2SpotFleetRequest`
<a name="ec2_CancelSpotFleetRequests_powershell_topic"></a>

以下代码示例演示了如何使用 `Stop-EC2SpotFleetRequest`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例取消指定的竞价型实例集请求并终止关联的竞价型实例。**  

```
Stop-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TerminateInstance $true
```
**示例 2：此示例取消指定的竞价型实例集请求，但不终止关联的竞价型实例。**  

```
Stop-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TerminateInstance $false
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CancelSpotFleetRequests](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Stop-EC2SpotInstanceRequest`
<a name="ec2_CancelSpotInstanceRequests_powershell_topic"></a>

以下代码示例演示了如何使用 `Stop-EC2SpotInstanceRequest`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例取消指定的竞价型实例请求。**  

```
Stop-EC2SpotInstanceRequest -SpotInstanceRequestId sir-12345678
```
**输出**：  

```
SpotInstanceRequestId    State
---------------------    -----
sir-12345678             cancelled
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CancelSpotInstanceRequests](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Unregister-EC2Address`
<a name="ec2_DisassociateAddress_powershell_topic"></a>

以下代码示例演示了如何使用 `Unregister-EC2Address`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的弹性 IP 地址与 VPC 中的指定实例取消关联。**  

```
Unregister-EC2Address -AssociationId eipassoc-12345678
```
**示例 2：此示例在 EC2-Classic 中取消指定弹性 IP 地址与指定实例的关联。**  

```
Unregister-EC2Address -PublicIp 203.0.113.17
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DisassociateAddress](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Unregister-EC2Image`
<a name="ec2_DeregisterImage_powershell_topic"></a>

以下代码示例演示了如何使用 `Unregister-EC2Image`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例取消注册指定的 AMI。**  

```
Unregister-EC2Image -ImageId ami-12345678
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeregisterImage](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Unregister-EC2PrivateIpAddress`
<a name="ec2_UnassignPrivateIpAddresses_powershell_topic"></a>

以下代码示例演示了如何使用 `Unregister-EC2PrivateIpAddress`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的网络接口取消分配指定的私有 IP 地址。**  

```
Unregister-EC2PrivateIpAddress -NetworkInterfaceId eni-1a2b3c4d -PrivateIpAddress 10.0.0.82
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UnassignPrivateIpAddresses](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Unregister-EC2RouteTable`
<a name="ec2_DisassociateRouteTable_powershell_topic"></a>

以下代码示例演示了如何使用 `Unregister-EC2RouteTable`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例移除路由表和子网之间的指定关联。**  

```
Unregister-EC2RouteTable -AssociationId rtbassoc-1a2b3c4d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DisassociateRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Update-EC2SecurityGroupRuleIngressDescription`
<a name="ec2_UpdateSecurityGroupRuleDescriptionsIngress_powershell_topic"></a>

以下代码示例演示了如何使用 `Update-EC2SecurityGroupRuleIngressDescription`。

**适用于 PowerShell V5 的工具**  
**示例 1：更新现有入口（入站）安全组规则的描述。**  

```
$existingInboundRule = Get-EC2SecurityGroupRule -SecurityGroupRuleId "sgr-1234567890"
$ruleWithUpdatedDescription = [Amazon.EC2.Model.SecurityGroupRuleDescription]@{
  "SecurityGroupRuleId" = $existingInboundRule.SecurityGroupRuleId
  "Description" = "Updated rule description"
}

Update-EC2SecurityGroupRuleIngressDescription -GroupId $existingInboundRule.GroupId -SecurityGroupRuleDescription $ruleWithUpdatedDescription
```
**示例 2：移除现有入口（入站）安全组规则的描述（通过在请求中省略该参数）。**  

```
$existingInboundRule = Get-EC2SecurityGroupRule -SecurityGroupRuleId "sgr-1234567890"
$ruleWithoutDescription = [Amazon.EC2.Model.SecurityGroupRuleDescription]@{
  "SecurityGroupRuleId" = $existingInboundRule.SecurityGroupRuleId
}

Update-EC2SecurityGroupRuleIngressDescription -GroupId $existingInboundRule.GroupId -SecurityGroupRuleDescription $ruleWithoutDescription
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateSecurityGroupRuleDescriptionsIngress](https://docs.aws.amazon.com/powershell/v5/reference)中的。