

第 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)

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Tools for PowerShell V5 的 Amazon EC2 範例
<a name="powershell_ec2_code_examples"></a>

下列程式碼範例示範如何使用 AWS Tools for PowerShell V5 搭配 Amazon EC2 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `Add-EC2CapacityReservation`。

**Tools for 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 參考 (V5)》**中的 [CreateCapacityReservation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Add-EC2InternetGateway`。

**Tools for 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 參考 (V5)》**中的 [AttachInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Add-EC2NetworkInterface`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的網路介面連接到指定的執行個體。**  

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

```
eni-attach-1a2b3c4d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AttachNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Add-EC2Volume`。

**Tools for 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 參考 (V5)》**中的 [AttachVolume](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Add-EC2VpnGateway`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的虛擬私有閘道，連接至指定的 VPC。**  

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

```
State        VpcId
-----        -----
attaching    vpc-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AttachVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Approve-EC2VpcPeeringConnection`。

**Tools for 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 參考 (V5)》**中的 [AcceptVpcPeeringConnection](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Confirm-EC2ProductInstance`。

**Tools for PowerShell V5**  
**範例 1：此範例會判斷指定的產品程式碼，是否與指定的執行個體相關聯。**  

```
Confirm-EC2ProductInstance -ProductCode 774F4FF8 -InstanceId i-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ConfirmProductInstance](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Copy-EC2Image`。

**Tools for 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 參考 (V5)》**中的 [CopyImage](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Copy-EC2Snapshot`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的快照從「歐盟 (愛爾蘭)」區域，複製到「美國西部 (奧勒岡)」區域。**  

```
Copy-EC2Snapshot -SourceRegion eu-west-1 -SourceSnapshotId snap-12345678 -Region us-west-2
```
**範例 2：如果您設定預設區域，並省略區域參數，預設目的地區域即為預設區域。**  

```
Set-DefaultAWSRegion us-west-2
Copy-EC2Snapshot -SourceRegion eu-west-1 -SourceSnapshotId snap-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CopySnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Deny-EC2VpcPeeringConnection`。

**Tools for PowerShell V5**  
**範例 1：上述範例會拒絕 VpcPeering 請求 id pcx-01a2b3ce45fe67eb8 的請求**  

```
Deny-EC2VpcPeeringConnection -VpcPeeringConnectionId pcx-01a2b3ce45fe67eb8
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RejectVpcPeeringConnection](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Disable-EC2VgwRoutePropagation`。

**Tools for PowerShell V5**  
**範例 1：此範例會禁用 VGW，不讓它將路由自動傳播到指定的路由表。**  

```
Disable-EC2VgwRoutePropagation -RouteTableId rtb-12345678 -GatewayId vgw-1a2b3c4d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisableVgwRoutePropagation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Disable-EC2VpcClassicLink`。

**Tools for PowerShell V5**  
**範例 1：此範例停用 vpc-01e23c4a5d6db78e9 的 EC2VpcClassicLink。範例會傳回 True 或 False**  

```
Disable-EC2VpcClassicLink -VpcId vpc-01e23c4a5d6db78e9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisableVpcClassicLink](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Disable-EC2VpcClassicLinkDnsSupport`。

**Tools for PowerShell V5**  
**範例 1：此範例會停用 vpc-0b12d3456a7e8910d 的 ClassicLink DNS 支援**  

```
Disable-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisableVpcClassicLinkDnsSupport](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Dismount-EC2InternetGateway`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的網際網路閘道與指定的 VPC 分開。**  

```
Dismount-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d -VpcId vpc-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DetachInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Dismount-EC2NetworkInterface`。

**Tools for PowerShell V5**  
**範例 1：此範例會移除網路介面與執行個體之間的指定連接。**  

```
Dismount-EC2NetworkInterface -AttachmentId eni-attach-1a2b3c4d -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DetachNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Dismount-EC2Volume`。

**Tools for 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 參考 (V5)》**中的 [DetachVolume](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Dismount-EC2VpnGateway`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的虛擬私有閘道與指定的 VPC 分開。**  

```
Dismount-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DetachVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2CapacityReservation`。

**Tools for PowerShell V5**  
**範例 1：此範例透過將執行個體計數變更為 1，修改 CapacityReservationId cr-0c1f2345db6f7cdba**  

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

```
True
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifyCapacityReservation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2Host`。

**Tools for PowerShell V5**  
**範例 1：此範例會將專用主機 h-01e23f4cd567890f3 的 AutoPlacement 設定修改為關閉**  

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

```
Successful            Unsuccessful
----------            ------------
{h-01e23f4cd567890f3} {}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifyHosts](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2IdFormat`。

**Tools for PowerShell V5**  
**範例 1：此範例會啟用指定資源類型的較長 ID 格式。**  

```
Edit-EC2IdFormat -Resource instance -UseLongId $true
```
**範例 2：此範例會停用指定資源類型的較長 ID 格式。**  

```
Edit-EC2IdFormat -Resource instance -UseLongId $false
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifyIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2ImageAttribute`。

**Tools for 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 參考 (V5)》**中的 [ModifyImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2InstanceAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例會修改指定執行個體的執行個體類型。**  

```
Edit-EC2InstanceAttribute -InstanceId i-12345678 -InstanceType m3.medium
```
**範例 2：此範例透過指定 "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：此範例會啟用指定之執行個體的來源/目的地檢查。若要讓執行個體執行 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 參考 (V5)》**中的 [ModifyInstanceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2InstanceCreditSpecification`。

**Tools for 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 參考 (V5)》**中的 [ModifyInstanceCreditSpecification](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2NetworkInterfaceAttribute`。

**Tools for 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：此範例會停用指定網路介面的來源/目的地檢查。**  

```
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -SourceDestCheck $false
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifyNetworkInterfaceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2ReservedInstance`。

**Tools for 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 參考 (V5)》**中的 [ModifyReservedInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2SnapshotAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例透過設定其 CreateVolumePermission 屬性，將指定的快照設為公有。**  

```
Edit-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute CreateVolumePermission -OperationType Add -GroupName all
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifySnapshotAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2SpotFleetRequest`。

**Tools for PowerShell V5**  
**範例 1：此範例會更新指定 Spot 機群請求的目標容量。**  

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

```
True
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifySpotFleetRequest](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2SubnetAttribute`。

**Tools for 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 參考 (V5)》**中的 [ModifySubnetAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2VolumeAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例會修改指定磁碟區的指定屬性。由於資料可能不一致，磁碟區的 I/O 操作在暫停後會自動恢復。**  

```
Edit-EC2VolumeAttribute -VolumeId vol-12345678 -AutoEnableIO $true
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ModifyVolumeAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Edit-EC2VpcAttribute`。

**Tools for 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 參考 (V5)》**中的 [ModifyVpcAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Enable-EC2VgwRoutePropagation`。

**Tools for PowerShell V5**  
**範例 1：此範例可讓指定的 VGW 自動將路由傳播至指定的路由表。**  

```
Enable-EC2VgwRoutePropagation -RouteTableId rtb-12345678 -GatewayId vgw-1a2b3c4d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnableVgwRoutePropagation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Enable-EC2VolumeIO`。

**Tools for PowerShell V5**  
**範例 1：如果停用 I/O 操作，此範例就會啟用指定磁碟區的 I/O 操作。**  

```
Enable-EC2VolumeIO -VolumeId vol-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnableVolumeIo](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Enable-EC2VpcClassicLink`。

**Tools for PowerShell V5**  
**範例 1：此範例會啟用 ClassicLink 的 VPC vpc-0123456b789b0d12f**  

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

```
True
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnableVpcClassicLink](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Enable-EC2VpcClassicLinkDnsSupport`。

**Tools for PowerShell V5**  
**範例 1：此範例可讓 vpc-0b12d3456a7e8910d 支援 ClassicLink 的 DNS 主機名稱解析**  

```
Enable-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d -Region eu-west-1
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnableVpcClassicLinkDnsSupport](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2AccountAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例描述您是否可以將執行個體啟動到該區域中的 EC2-Classic 和 EC2-VPC 中，或只能啟動到 EC2-VPC 中。**  

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

```
AttributeValue
--------------
EC2
VPC
```
**範例 2：此範例描述您的預設 VPC，或如果區域中沒有預設 VPC，則為 'none'**。  

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

```
AttributeValue
--------------
vpc-12345678
```
**範例 3：此範例描述您可以執行的隨需執行個體數量上限。**  

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

```
AttributeValue
--------------
20
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeAccountAttributes](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Address`。

**Tools for 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：此範例會擷取所有具有其配置 ID、關聯 ID 和執行個體 ID 的彈性 IP**  

```
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' 且符合標籤索引鍵 'Category' 的 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 參考 (V5)》**中的 [DescribeAddresses](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2AvailabilityZone`。

**Tools for 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 參考 (V5)》**中的 [DescribeAvailabilityZones](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2BundleTask`。

**Tools for 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 參考 (V5)》**中的 [DescribeBundleTasks](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2CapacityReservation`。

**Tools for 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 參考 (V5)》**中的 [DescribeCapacityReservations](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2ConsoleOutput`。

**Tools for 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 參考 (V5)》**中的 [GetConsoleOutput](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2CustomerGateway`。

**Tools for 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 參考 (V5)》**中的 [DescribeCustomerGateways](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2DhcpOption`。

**Tools for 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 參考 (V5)》**中的 [DescribeDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2FlowLog`。

**Tools for 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 參考 (V5)》**中的 [DescribeFlowLogs](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Host`。

**Tools for 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-01e23f4cd567899f1 的 AvailableInstanceCapacity**  

```
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 參考 (V5)》**中的 [DescribeHosts](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2HostReservationOffering`。

**Tools for PowerShell V5**  
**範例 1：此範例描述專用主機保留，可供購買給指定篩選條件 'instance-family'，其中 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 參考 (V5)》**中的 [DescribeHostReservationOfferings](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2HostReservationPurchasePreview`。

**Tools for 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 參考 (V5)》**中的 [GetHostReservationPurchasePreview](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2IdFormat`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定資源類型的 ID 格式。**  

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

```
Resource       UseLongIds
--------       ----------
instance       False
```
**範例 2：此範例描述支援較長 ID 的所有資源類型的 ID 格式。**  

```
Get-EC2IdFormat
```
**輸出：**  

```
Resource       UseLongIds
--------       ----------
reservation    False
instance       False
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2IdentityIdFormat`。

**Tools for 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 參考 (V5)》**中的 [DescribeIdentityIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Image`。

**Tools for 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：此範例描述您擁有的 AMI。**  

```
Get-EC2Image -owner self
```
**範例 3：此範例描述執行 Microsoft Windows Server 的公有 AMI。**  

```
Get-EC2Image -Filter @{ Name="platform"; Values="windows" }
```
**範例 4：此範例描述 'us-west-2' 區域中的所有公有 AMI。**  

```
Get-EC2Image -Region us-west-2
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeImages](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2ImageAttribute`。

**Tools for 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 參考 (V5)》**中的 [DescribeImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2ImportImageTask`。

**Tools for 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 參考 (V5)》**中的 [DescribeImportImageTasks](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2ImportSnapshotTask`。

**Tools for 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 參考 (V5)》**中的 [DescribeImportSnapshotTasks](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Instance`。

**Tools for 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：此範例會驗證使用 DryRun 參數取得 EC2 執行個體的許可，而不會實際擷取。注意：如果成功，則會擲回例外狀況，這是預期的行為。**  

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

```
Get-EC2Instance: Request would have succeeded, but DryRun flag is set.
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2InstanceAttribute`。

**Tools for 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：此範例描述指定之執行個體的 'instanceInitiatedShutdownBehavior' 屬性。**  

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

```
InstanceInitiatedShutdownBehavior : stop
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeInstanceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2InstanceMetadata`。

**Tools for 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：傳回用來啟動執行個體的 Amazon Machine Image (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 參考 (V5)》**中的 [Get-EC2InstanceMetadata](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2InstanceStatus`。

**Tools for 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 參考 (V5)》**中的 [DescribeInstanceStatus](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2InternetGateway`。

**Tools for 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 參考 (V5)》**中的 [DescribeInternetGateways](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2KeyPair`。

**Tools for 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 參考 (V5)》**中的 [DescribeKeyPairs](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2NetworkAcl`。

**Tools for 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：此範例描述您的所有網路 ACL。**  

```
Get-EC2NetworkAcl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeNetworkAcls](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2NetworkInterface`。

**Tools for 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 參考 (V5)》**中的 [DescribeNetworkInterfaces](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2NetworkInterfaceAttribute`。

**Tools for 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 參考 (V5)》**中的 [DescribeNetworkInterfaceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2PasswordData`。

**Tools for PowerShell V5**  
**範例 1：此範例會解密 Amazon EC2 指派給指定之 Windows 執行個體管理員帳戶的密碼。由於指定了 pem 檔案，因此會自動採用 -Decrypt 參數的設定。**  

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

```
mYZ(PA9?C)Q
```
**範例 2：（僅限 Windows PowerShell) 檢查執行個體，以判斷用來啟動執行個體的金鑰對名稱，然後嘗試在 AWS Toolkit 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 參考 (V5)》**中的 [GetPasswordData](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2PlacementGroup`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的置放群組。**  

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

```
GroupName             State        Strategy
---------             -----        --------
my-placement-group    available    cluster
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribePlacementGroups](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2PrefixList`。

**Tools for 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 參考 (V5)》**中的 [DescribePrefixLists](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Region`。

**Tools for 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 參考 (V5)》**中的 [DescribeRegions](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2RouteTable`。

**Tools for 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 參考 (V5)》**中的 [DescribeRouteTables](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2ScheduledInstance`。

**Tools for 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 參考 (V5)》**中的 [DescribeScheduledInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2ScheduledInstanceAvailability`。

**Tools for 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 參考 (V5)》**中的 [DescribeScheduledInstanceAvailability](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SecurityGroup`。

**Tools for 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 參考 (V5)》**中的 [DescribeSecurityGroups](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Snapshot`。

**Tools for 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' 之 'Name' 標籤的快照。**  

```
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 參考 (V5)》**中的 [DescribeSnapshots](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SnapshotAttribute`。

**Tools for 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 參考 (V5)》**中的 [DescribeSnapshotAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SpotDatafeedSubscription`。

**Tools for PowerShell V5**  
**範例 1：此範例描述您的 Spot 執行個體資料饋送。**  

```
Get-EC2SpotDatafeedSubscription
```
**輸出：**  

```
Bucket  : amzn-s3-demo-bucket
Fault   :
OwnerId : 123456789012
Prefix  : spotdata
State   : Active
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SpotFleetInstance`。

**Tools for PowerShell V5**  
**範例 1：此範例描述與指定 Spot 機群請求相關聯的執行個體。**  

```
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 參考 (V5)》**中的 [DescribeSpotFleetInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SpotFleetRequest`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 Spot 機群請求。**  

```
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：此範例描述所有 Spot 機群請求。**  

```
Get-EC2SpotFleetRequest
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeSpotFleetRequests](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SpotFleetRequestHistory`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定 Spot 機群請求的歷程記錄。**  

```
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 參考 (V5)》**中的 [DescribeSpotFleetRequestHistory](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SpotInstanceRequest`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 Spot 執行個體請求。**  

```
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：此範例描述所有 Spot 執行個體請求。**  

```
Get-EC2SpotInstanceRequest
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeSpotInstanceRequests](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2SpotPriceHistory`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定執行個體類型和可用區域中，Spot 價格歷程記錄中最後 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 參考 (V5)》**中的 [DescribeSpotPriceHistory](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Subnet`。

**Tools for 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 參考 (V5)》**中的 [DescribeSubnets](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Tag`。

**Tools for 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：此範例會取得具有 'no' 值之標籤 'auto-delete' 的所有資源，並在下一個管道中進一步篩選，以僅剖析 'instance' 資源類型，最終為每個執行個體資源建立 '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 參考 (V5)》**中的 [DescribeTags](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Volume`。

**Tools for 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：此範例描述狀態為 'available' 的 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 參考 (V5)》**中的 [DescribeVolumes](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VolumeAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定之磁碟區的指定屬性。**  

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

```
AutoEnableIO    ProductCodes    VolumeId
------------    ------------    --------
False           {}              vol-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeVolumeAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VolumeStatus`。

**Tools for 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 參考 (V5)》**中的 [DescribeVolumeStatus](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2Vpc`。

**Tools for 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：此範例描述符合指定篩選條件的 VPC (即具有符合值 '10.0.0.0/16' 且處於 'available' 狀態的 CIDR)。**  

```
Get-EC2Vpc -Filter @{Name="cidr"; Values="10.0.0.0/16"},@{Name="state";Values="available"}
```
**範例 4：此範例描述您的所有 VPC。**  

```
Get-EC2Vpc
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeVpcs](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpcAttribute`。

**Tools for 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 參考 (V5)》**中的 [DescribeVpcAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpcClassicLink`。

**Tools for PowerShell V5**  
**範例 1：上述範例傳回具有該區域 ClassicLinkEnabled 狀態的所有 VPC**  

```
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 參考 (V5)》**中的 [DescribeVpcClassicLink](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpcClassicLinkDnsSupport`。

**Tools for PowerShell V5**  
**範例 1：此範例描述區域 eu-west-1 的 VPC 的 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 參考 (V5)》**中的 [DescribeVpcClassicLinkDnsSupport](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpcEndpoint`。

**Tools for 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 參考 (V5)》**中的 [DescribeVpcEndpoints](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpcEndpointService`。

**Tools for 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 端點服務，並傳回符合 "ssm" 的 ServiceNames**  

```
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 參考 (V5)》**中的 [DescribeVpcEndpointServices](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpnConnection`。

**Tools for 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 參考 (V5)》**中的 [DescribeVpnConnections](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-EC2VpnGateway`。

**Tools for 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 參考 (V5)》**中的 [DescribeVpnGateways](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Grant-EC2SecurityGroupEgress`。

**Tools for 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 參考 (V5)》**中的 [AuthorizeSecurityGroupEgress](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Grant-EC2SecurityGroupIngress`。

**Tools for 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：此範例會將來自指定來源安全群組 (sg-1a2b3c4d) 的 TCP 連接埠 8081 存取權，授予指定的安全群組 (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 新增至安全群組 sg-1234abcd 的傳入規則，以描述 TCP 連接埠 22 流量。**  

```
$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 參考 (V5)》**中的 [AuthorizeSecurityGroupIngress](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Import-EC2Image`。

**Tools for PowerShell V5**  
**範例 1：此範例會使用冪等性字符，將單一磁碟虛擬機器映像從指定的 Amazon S3 儲存貯體匯入 Amazon EC2。此範例要求具有預設名稱 'vmimport' 的 VM Import 服務角色必須存在，其政策允許 Amazon EC2 存取指定的儲存貯體，如 VM Import 先決條件主題所述。若要使用自訂角色，請使用 `-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 參考 (V5)》**中的 [ImportImage](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Import-EC2KeyPair`。

**Tools for 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 參考 (V5)》**中的 [ImportKeyPair](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Import-EC2Snapshot`。

**Tools for PowerShell V5**  
**範例 1：此範例會將格式為 'VMDK' 的 VM 磁碟映像，匯入 Amazon EBS 快照。此範例需要預設名稱為 'vmimport' 的 VM Import 服務角色，以及允許 Amazon EC2 存取指定的儲存貯體的政策，如 http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/VMImportPrerequisites.html 中的 `VM Import Prequisites` 主題所述。若要使用自訂角色，請使用 `-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 參考 (V5)》**中的 [ImportSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Move-EC2AddressToVpc`。

**Tools for 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 參考 (V5)》**中的 [MoveAddressToVpc](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Address`。

**Tools for PowerShell V5**  
**範例 1：此範例會配置要與 VPC 中的執行個體搭配使用的彈性 IP 位址。**  

```
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 參考 (V5)》**中的 [AllocateAddress](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2CustomerGateway`。

**Tools for 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 參考 (V5)》**中的 [CreateCustomerGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2DhcpOption`。

**Tools for 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 參考 (V5)》**中的 [CreateDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2FlowLog`。

**Tools for PowerShell V5**  
**範例 1：此範例會使用 'Admin' 角色的權限，為子網路 subnet-1d234567 建立 EC2 流程日誌，並將其傳送至名為 'subnet1-log' 的 cloud-watch-log，以用於所有 'REJECT' 流量**  

```
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 參考 (V5)》**中的 [CreateFlowLogs](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Host`。

**Tools for PowerShell V5**  
**範例 1：此範例會將給定執行個體類型和可用區域的專用主機，配置給您的帳戶**  

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

```
h-01e23f4cd567890f3
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AllocateHosts](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2HostReservation`。

**Tools for PowerShell V5**  
**範例 1：此範例會購買預留服務 hro-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 參考 (V5)》**中的 [PurchaseHostReservation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Image`。

**Tools for 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 參考 (V5)》**中的 [CreateImage](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Instance`。

**Tools for 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 AMI，請使用 Get-SSMLatestEC2Image 取得其 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：此請求會啟動兩個執行個體，並將具有 Web 伺服器索引鍵和生產值的標籤，套用至執行個體。請求也會將具有成本中心索引鍵和 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 參考 (V5)》**中的 [RunInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2InstanceExportTask`。

**Tools for 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 參考 (V5)》**中的 [CreateInstanceExportTask](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2InternetGateway`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立網際網路閘道。**  

```
New-EC2InternetGateway
```
**輸出：**  

```
Attachments    InternetGatewayId    Tags
-----------    -----------------    ----
{}             igw-1a2b3c4d         {}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2KeyPair`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立金鑰對，並在具有指定名稱的檔案中，擷取 PEM 編碼的 RSA 私有金鑰。當您使用 PowerShell 時，編碼必須設定為 ascii，才能產生有效的金鑰。如需詳細資訊，請參閱《 AWS 命令列界面使用者指南》中的建立、顯示和刪除 Amazon 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 參考 (V5)》**中的 [CreateKeyPair](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2NetworkAcl`。

**Tools for 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 參考 (V5)》**中的 [CreateNetworkAcl](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2NetworkAclEntry`。

**Tools for 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 參考 (V5)》**中的 [CreateNetworkAclEntry](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2NetworkInterface`。

**Tools for 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 參考 (V5)》**中的 [CreateNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2PlacementGroup`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立具有指定名稱的置放群組。**  

```
New-EC2PlacementGroup -GroupName my-placement-group -Strategy cluster
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreatePlacementGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Route`。

**Tools for PowerShell V5**  
**範例 1：此範例會為指定的路由表建立指定的路由。路由符合所有流量，並將其傳送至指定的網際網路閘道。**  

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

```
True
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateRoute](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2RouteTable`。

**Tools for 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 參考 (V5)》**中的 [CreateRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2ScheduledInstance`。

**Tools for 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 參考 (V5)》**中的 [RunScheduledInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2ScheduledInstancePurchase`。

**Tools for 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 參考 (V5)》**中的 [PurchaseScheduledInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2SecurityGroup`。

**Tools for 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 參考 (V5)》**中的 [CreateSecurityGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Snapshot`。

**Tools for 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 參考 (V5)》**中的 [CreateSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2SpotDatafeedSubscription`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立 Spot 執行個體資料饋送。**  

```
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 參考 (V5)》**中的 [CreateSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Subnet`。

**Tools for 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 參考 (V5)》**中的 [CreateSubnet](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Tag`。

**Tools for 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 參數的標籤。**  

```
$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 參考 (V5)》**中的 [CreateTags](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-EC2Volume`。

**Tools for 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：此範例請求會建立磁碟區，並套用具有堆疊索引鍵和生產值的標籤。**  

```
$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 參考 (V5)》**中的 [CreateVolume](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-EC2Vpc`
<a name="ec2_CreateVpc_powershell_topic"></a>

以下程式碼範例顯示如何使用 `New-EC2Vpc`。

**Tools for 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 參考 (V5)》**中的 [CreateVpc](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-EC2VpcEndpoint`
<a name="ec2_CreateVpcEndpoint_powershell_topic"></a>

以下程式碼範例顯示如何使用 `New-EC2VpcEndpoint`。

**Tools for 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 參考 (V5)》**中的 [CreateVpcEndpoint](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-EC2VpnConnection`
<a name="ec2_CreateVpnConnection_powershell_topic"></a>

以下程式碼範例顯示如何使用 `New-EC2VpnConnection`。

**Tools for 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 參考 (V5)》**中的 [CreateVpnConnection](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-EC2VpnConnectionRoute`
<a name="ec2_CreateVpnConnectionRoute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `New-EC2VpnConnectionRoute`。

**Tools for PowerShell V5**  
**範例 1：此範例會為指定的 VPN 連接建立指定的靜態路由。**  

```
New-EC2VpnConnectionRoute -VpnConnectionId vpn-12345678 -DestinationCidrBlock 11.12.0.0/16
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateVpnConnectionRoute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-EC2VpnGateway`
<a name="ec2_CreateVpnGateway_powershell_topic"></a>

以下程式碼範例顯示如何使用 `New-EC2VpnGateway`。

**Tools for 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 參考 (V5)》**中的 [CreateVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-EC2Address`
<a name="ec2_AssociateAddress_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Register-EC2Address`。

**Tools for 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 參考 (V5)》**中的 [AssociateAddress](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-EC2DhcpOption`
<a name="ec2_AssociateDhcpOptions_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Register-EC2DhcpOption`。

**Tools for 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 參考 (V5)》**中的 [AssociateDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-EC2Image`
<a name="ec2_RegisterImage_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Register-EC2Image`。

**Tools for 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 參考 (V5)》**中的 [RegisterImage](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-EC2PrivateIpAddress`
<a name="ec2_AssignPrivateIpAddresses_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Register-EC2PrivateIpAddress`。

**Tools for 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 參考 (V5)》**中的 [AssignPrivateIpAddresses](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-EC2RouteTable`
<a name="ec2_AssociateRouteTable_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Register-EC2RouteTable`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的路由表，與指定的子網路相關聯。**  

```
Register-EC2RouteTable -RouteTableId rtb-1a2b3c4d -SubnetId subnet-1a2b3c4d
```
**輸出：**  

```
rtbassoc-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AssociateRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Address`
<a name="ec2_ReleaseAddress_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Address`。

**Tools for 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 參考 (V5)》**中的 [ReleaseAddress](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2CapacityReservation`
<a name="ec2_CancelCapacityReservation_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2CapacityReservation`。

**Tools for 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 參考 (V5)》**中的 [CancelCapacityReservation](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2CustomerGateway`
<a name="ec2_DeleteCustomerGateway_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2CustomerGateway`。

**Tools for 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 參考 (V5)》**中的 [DeleteCustomerGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2DhcpOption`
<a name="ec2_DeleteDhcpOptions_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2DhcpOption`。

**Tools for 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 參考 (V5)》**中的 [DeleteDhcpOptions](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2FlowLog`
<a name="ec2_DeleteFlowLogs_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2FlowLog`。

**Tools for 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 參考 (V5)》**中的 [DeleteFlowLogs](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Host`
<a name="ec2_ReleaseHosts_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Host`。

**Tools for PowerShell V5**  
**範例 1：此範例會發行給定的主機 ID h-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 參考 (V5)》**中的 [ReleaseHosts](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Instance`
<a name="ec2_TerminateInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Instance`。

**Tools for PowerShell V5**  
**範例 1：此範例會終止指定的執行個體 (執行個體可能正在執行，或處於 'stopped' 狀態)。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 參考 (V5)》**中的 [TerminateInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2InternetGateway`
<a name="ec2_DeleteInternetGateway_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2InternetGateway`。

**Tools for 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 參考 (V5)》**中的 [DeleteInternetGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2KeyPair`
<a name="ec2_DeleteKeyPair_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2KeyPair`。

**Tools for 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 參考 (V5)》**中的 [DeleteKeyPair](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2NetworkAcl`
<a name="ec2_DeleteNetworkAcl_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2NetworkAcl`。

**Tools for 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 參考 (V5)》**中的 [DeleteNetworkAcl](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2NetworkAclEntry`
<a name="ec2_DeleteNetworkAclEntry_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2NetworkAclEntry`。

**Tools for 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 參考 (V5)》**中的 [DeleteNetworkAclEntry](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2NetworkInterface`
<a name="ec2_DeleteNetworkInterface_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2NetworkInterface`。

**Tools for 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 參考 (V5)》**中的 [DeleteNetworkInterface](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2PlacementGroup`
<a name="ec2_DeletePlacementGroup_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2PlacementGroup`。

**Tools for 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 參考 (V5)》**中的 [DeletePlacementGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Route`
<a name="ec2_DeleteRoute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Route`。

**Tools for 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 參考 (V5)》**中的 [DeleteRoute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2RouteTable`
<a name="ec2_DeleteRouteTable_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2RouteTable`。

**Tools for 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 參考 (V5)》**中的 [DeleteRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2SecurityGroup`
<a name="ec2_DeleteSecurityGroup_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2SecurityGroup`。

**Tools for 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 參考 (V5)》**中的 [DeleteSecurityGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Snapshot`
<a name="ec2_DeleteSnapshot_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Snapshot`。

**Tools for 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 參考 (V5)》**中的 [DeleteSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2SpotDatafeedSubscription`
<a name="ec2_DeleteSpotDatafeedSubscription_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2SpotDatafeedSubscription`。

**Tools for PowerShell V5**  
**範例 1：此範例會刪除您的 Spot 執行個體資料饋送。除非也指定 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 參考 (V5)》**中的 [DeleteSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Subnet`
<a name="ec2_DeleteSubnet_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Subnet`。

**Tools for 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 參考 (V5)》**中的 [DeleteSubnet](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Tag`
<a name="ec2_DeleteTags_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Tag`。

**Tools for 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 參考 (V5)》**中的 [DeleteTags](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Volume`
<a name="ec2_DeleteVolume_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Volume`。

**Tools for 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 參考 (V5)》**中的 [DeleteVolume](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2Vpc`
<a name="ec2_DeleteVpc_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2Vpc`。

**Tools for 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 參考 (V5)》**中的 [DeleteVpc](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2VpnConnection`
<a name="ec2_DeleteVpnConnection_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2VpnConnection`。

**Tools for 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 參考 (V5)》**中的 [DeleteVpnConnection](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2VpnConnectionRoute`
<a name="ec2_DeleteVpnConnectionRoute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2VpnConnectionRoute`。

**Tools for 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 參考 (V5)》**中的 [DeleteVpnConnectionRoute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-EC2VpnGateway`
<a name="ec2_DeleteVpnGateway_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-EC2VpnGateway`。

**Tools for 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 參考 (V5)》**中的 [DeleteVpnGateway](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Request-EC2SpotFleet`
<a name="ec2_RequestSpotFleet_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Request-EC2SpotFleet`。

**Tools for PowerShell V5**  
**範例 1：此範例會在可用區域中，以指定執行個體類型的最低價格，建立 Spot 機群請求。如果您的帳戶僅支援 EC2-VPC，Spot 機群會在具有預設子網路的最低價格可用區域中，啟動執行個體。如果您的帳戶支援 EC2-Classic，Spot 機群會在價格最低的可用區域中，啟動 EC2-Classic 中的執行個體。請注意，您支付的價格不會超過請求的指定 Spot 價格。**  

```
$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 參考 (V5)》**中的 [RequestSpotFleet](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Request-EC2SpotInstance`
<a name="ec2_RequestSpotInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Request-EC2SpotInstance`。

**Tools for PowerShell V5**  
**範例 1：此範例會請求指定子網路中的一次性 Spot 執行個體。請注意，必須為包含指定子網路的 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 參考 (V5)》**中的 [RequestSpotInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Reset-EC2ImageAttribute`
<a name="ec2_ResetImageAttribute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Reset-EC2ImageAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例會將 'launchPermission' 屬性重設為其預設值。根據預設，AMI 為私有。**  

```
Reset-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ResetImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Reset-EC2InstanceAttribute`
<a name="ec2_ResetInstanceAttribute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Reset-EC2InstanceAttribute`。

**Tools for 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：此範例會為指定的執行個體重設 'instanceInitiatedShutdownBehavior' 屬性。**  

```
Reset-EC2InstanceAttribute -InstanceId i-12345678 -Attribute instanceInitiatedShutdownBehavior
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ResetInstanceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Reset-EC2NetworkInterfaceAttribute`
<a name="ec2_ResetNetworkInterfaceAttribute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Reset-EC2NetworkInterfaceAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例會為指定的網路介面重設來源/目的地檢查作業。**  

```
Reset-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -SourceDestCheck
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ResetNetworkInterfaceAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Reset-EC2SnapshotAttribute`
<a name="ec2_ResetSnapshotAttribute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Reset-EC2SnapshotAttribute`。

**Tools for PowerShell V5**  
**範例 1：此範例會重設指定快照的指定屬性。**  

```
Reset-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute CreateVolumePermission
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ResetSnapshotAttribute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Restart-EC2Instance`
<a name="ec2_RebootInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Restart-EC2Instance`。

**Tools for PowerShell V5**  
**範例 1：此範例會重新啟動指定的執行個體。**  

```
Restart-EC2Instance -InstanceId i-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RebootInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Revoke-EC2SecurityGroupEgress`
<a name="ec2_RevokeSecurityGroupEgress_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Revoke-EC2SecurityGroupEgress`。

**Tools for 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 參考 (V5)》**中的 [RevokeSecurityGroupEgress](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Revoke-EC2SecurityGroupIngress`
<a name="ec2_RevokeSecurityGroupIngress_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Revoke-EC2SecurityGroupIngress`。

**Tools for 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 參考 (V5)》**中的 [RevokeSecurityGroupIngress](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Send-EC2InstanceStatus`
<a name="ec2_ReportInstanceStatus_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Send-EC2InstanceStatus`。

**Tools for PowerShell V5**  
**範例 1：此範例會報告指定執行個體的狀態意見回饋。**  

```
Send-EC2InstanceStatus -Instance i-12345678 -Status impaired -ReasonCode unresponsive
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ReportInstanceStatus](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-EC2NetworkAclAssociation`
<a name="ec2_ReplaceNetworkAclAssociation_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Set-EC2NetworkAclAssociation`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的網路 ACL，與指定之網路 ACL 關聯的子網路建立關聯。**  

```
Set-EC2NetworkAclAssociation -NetworkAclId acl-12345678 -AssociationId aclassoc-1a2b3c4d
```
**輸出：**  

```
aclassoc-87654321
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ReplaceNetworkAclAssociation](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-EC2NetworkAclEntry`
<a name="ec2_ReplaceNetworkAclEntry_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Set-EC2NetworkAclEntry`。

**Tools for 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 參考 (V5)》**中的 [ReplaceNetworkAclEntry](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-EC2Route`
<a name="ec2_ReplaceRoute_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Set-EC2Route`。

**Tools for PowerShell V5**  
**範例 1：此範例會取代指定路由表的指定路由。新路由會將指定的流量，傳送至指定的虛擬私有閘道。**  

```
Set-EC2Route -RouteTableId rtb-1a2b3c4d -DestinationCidrBlock 10.0.0.0/24 -GatewayId vgw-1a2b3c4d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ReplaceRoute](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-EC2RouteTableAssociation`
<a name="ec2_ReplaceRouteTableAssociation_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Set-EC2RouteTableAssociation`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的路由表，與指定之路由表關聯的子網路建立關聯。**  

```
Set-EC2RouteTableAssociation -RouteTableId rtb-1a2b3c4d -AssociationId rtbassoc-12345678
```
**輸出：**  

```
rtbassoc-87654321
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ReplaceRouteTableAssociation](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Start-EC2Instance`
<a name="ec2_StartInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Start-EC2Instance`。

**Tools for 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 = New-Object Amazon.EC2.Model.Filter
$filter.Name = "instance-state-name"
$filter.Values = "stopped"

(Get-EC2Instance -Filter $filter).Instances | Start-EC2Instance
```
**範例 5：此範例會驗證使用 DryRun 參數啟動 EC2 執行個體的許可權，但不會實際啟動執行個體。注意：如果成功，則會擲回例外狀況，這是預期的行為。**  

```
Start-EC2Instance -InstanceId 'i-0abcdef123456' -Region 'us-west-1' -DryRun $true
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [StartInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Start-EC2InstanceMonitoring`
<a name="ec2_MonitorInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Start-EC2InstanceMonitoring`。

**Tools for PowerShell V5**  
**範例 1：此範例命令會啟用指定執行個體的詳細監控功能。**  

```
Start-EC2InstanceMonitoring -InstanceId i-12345678
```
**輸出：**  

```
InstanceId    Monitoring
----------    ----------
i-12345678    Amazon.EC2.Model.Monitoring
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [MonitorInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-EC2ImportTask`
<a name="ec2_CancelImportTask_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Stop-EC2ImportTask`。

**Tools for PowerShell V5**  
**範例 1：此範例會取消指定的匯入任務 (快照或映像匯入)。如有必要，可以使用 `-CancelReason` 參數提供原因。**  

```
Stop-EC2ImportTask -ImportTaskId import-ami-abcdefgh
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CancelImportTask](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-EC2Instance`
<a name="ec2_StopInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Stop-EC2Instance`。

**Tools for 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 參考 (V5)》**中的 [StopInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-EC2InstanceMonitoring`
<a name="ec2_UnmonitorInstances_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Stop-EC2InstanceMonitoring`。

**Tools for PowerShell V5**  
**範例 1：此範例命令會停用指定執行個體的詳細監控功能。**  

```
Stop-EC2InstanceMonitoring -InstanceId i-12345678
```
**輸出：**  

```
InstanceId    Monitoring
----------    ----------
i-12345678    Amazon.EC2.Model.Monitoring
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UnmonitorInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-EC2SpotFleetRequest`
<a name="ec2_CancelSpotFleetRequests_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Stop-EC2SpotFleetRequest`。

**Tools for PowerShell V5**  
**範例 1：此範例會取消指定的 Spot 機群請求，並終止相關聯的 Spot 執行個體。**  

```
Stop-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TerminateInstance $true
```
**範例 2：此範例會取消指定的 Spot 機群請求，但不會終止相關聯的 Spot 執行個體。**  

```
Stop-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TerminateInstance $false
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CancelSpotFleetRequests](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-EC2SpotInstanceRequest`
<a name="ec2_CancelSpotInstanceRequests_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Stop-EC2SpotInstanceRequest`。

**Tools for PowerShell V5**  
**範例 1：此範例會取消指定的 Spot 執行個體請求。**  

```
Stop-EC2SpotInstanceRequest -SpotInstanceRequestId sir-12345678
```
**輸出：**  

```
SpotInstanceRequestId    State
---------------------    -----
sir-12345678             cancelled
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CancelSpotInstanceRequests](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Unregister-EC2Address`
<a name="ec2_DisassociateAddress_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Unregister-EC2Address`。

**Tools for PowerShell V5**  
**範例 1：此範例會取消指定彈性 IP 位址與 VPC 中指定執行個體的關聯。**  

```
Unregister-EC2Address -AssociationId eipassoc-12345678
```
**範例 2：此範例會取消指定的彈性 IP 位址，與 EC2-Classic 中指定執行個體的關聯。**  

```
Unregister-EC2Address -PublicIp 203.0.113.17
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisassociateAddress](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Unregister-EC2Image`
<a name="ec2_DeregisterImage_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Unregister-EC2Image`。

**Tools for PowerShell V5**  
**範例 1：此範例會取消註冊指定的 AMI。**  

```
Unregister-EC2Image -ImageId ami-12345678
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeregisterImage](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Unregister-EC2PrivateIpAddress`
<a name="ec2_UnassignPrivateIpAddresses_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Unregister-EC2PrivateIpAddress`。

**Tools for PowerShell V5**  
**範例 1：此範例會從指定的網路介面，取消指派指定的私有 IP 位址。**  

```
Unregister-EC2PrivateIpAddress -NetworkInterfaceId eni-1a2b3c4d -PrivateIpAddress 10.0.0.82
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UnassignPrivateIpAddresses](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Unregister-EC2RouteTable`
<a name="ec2_DisassociateRouteTable_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Unregister-EC2RouteTable`。

**Tools for PowerShell V5**  
**範例 1：此範例會移除路由表與子網路之間指定的關聯。**  

```
Unregister-EC2RouteTable -AssociationId rtbassoc-1a2b3c4d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisassociateRouteTable](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-EC2SecurityGroupRuleIngressDescription`
<a name="ec2_UpdateSecurityGroupRuleDescriptionsIngress_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Update-EC2SecurityGroupRuleIngressDescription`。

**Tools for 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 參考 (V5)》**中的 [UpdateSecurityGroupRuleDescriptionsIngress](https://docs.aws.amazon.com/powershell/v5/reference)。