There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon EC2 examples using Tools for PowerShell V5
The following code examples show you how to perform actions and implement common scenarios by using the AWS Tools for PowerShell V5 with Amazon EC2.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use Add-EC2CapacityReservation.
- Tools for PowerShell V5
-
Example 1: This example creates a new Capacity Reservation with the specified attributes
Add-EC2CapacityReservation -InstanceType m4.xlarge -InstanceCount 2 -AvailabilityZone eu-west-1b -EbsOptimized True -InstancePlatform WindowsOutput:
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-
For API details, see CreateCapacityReservation in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Add-EC2InternetGateway.
- Tools for PowerShell V5
-
Example 1: This example attaches the specified Internet gateway to the specified VPC.
Add-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d -VpcId vpc-12345678Example 2: This example creates a VPC and an Internet gateway, and then attaches the Internet gateway to the VPC.
$vpc = New-EC2Vpc -CidrBlock 10.0.0.0/16 New-EC2InternetGateway | Add-EC2InternetGateway -VpcId $vpc.VpcId-
For API details, see AttachInternetGateway in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Add-EC2NetworkInterface.
- Tools for PowerShell V5
-
Example 1: This example attaches the specified network interface to the specified instance.
Add-EC2NetworkInterface -NetworkInterfaceId eni-12345678 -InstanceId i-1a2b3c4d -DeviceIndex 1Output:
eni-attach-1a2b3c4d-
For API details, see AttachNetworkInterface in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Add-EC2Volume.
- Tools for PowerShell V5
-
Example 1: This example attaches the specified volume to the specified instance and exposes it with the specified device name.
Add-EC2Volume -VolumeId vol-12345678 -InstanceId i-1a2b3c4d -Device /dev/sdhOutput:
AttachTime : 12/22/2015 1:53:58 AM DeleteOnTermination : False Device : /dev/sdh InstanceId : i-1a2b3c4d State : attaching VolumeId : vol-12345678-
For API details, see AttachVolume in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Add-EC2VpnGateway.
- Tools for PowerShell V5
-
Example 1: This example attaches the specified virtual private gateway to the specified VPC.
Add-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678Output:
State VpcId ----- ----- attaching vpc-12345678-
For API details, see AttachVpnGateway in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Approve-EC2VpcPeeringConnection.
- Tools for PowerShell V5
-
Example 1: This example approves the requested VpcPeeringConnectionId pcx-1dfad234b56ff78be
Approve-EC2VpcPeeringConnection -VpcPeeringConnectionId pcx-1dfad234b56ff78beOutput:
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-
For API details, see AcceptVpcPeeringConnection in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Confirm-EC2ProductInstance.
- Tools for PowerShell V5
-
Example 1: This example determines whether the specified product code is associated with the specified instance.
Confirm-EC2ProductInstance -ProductCode 774F4FF8 -InstanceId i-12345678-
For API details, see ConfirmProductInstance in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Copy-EC2Image.
- Tools for PowerShell V5
-
Example 1: This example copies the specified AMI in the 'EU (Ireland)' region to the 'US West (Oregon)' region. If -Region is not specified, the current default region is used as the destination region.
Copy-EC2Image -SourceRegion eu-west-1 -SourceImageId ami-12345678 -Region us-west-2 -Name "Copy of ami-12345678"Output:
ami-87654321-
For API details, see CopyImage in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Copy-EC2Snapshot.
- Tools for PowerShell V5
-
Example 1: This example copies the specified snapshot from the EU (Ireland) region to the US West (Oregon) region.
Copy-EC2Snapshot -SourceRegion eu-west-1 -SourceSnapshotId snap-12345678 -Region us-west-2Example 2: If you set a default region and omit the Region parameter, the default destination region is the default region.
Set-DefaultAWSRegion us-west-2 Copy-EC2Snapshot -SourceRegion eu-west-1 -SourceSnapshotId snap-12345678-
For API details, see CopySnapshot in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Deny-EC2VpcPeeringConnection.
- Tools for PowerShell V5
-
Example 1: The above example denies the request for VpcPeering request id pcx-01a2b3ce45fe67eb8
Deny-EC2VpcPeeringConnection -VpcPeeringConnectionId pcx-01a2b3ce45fe67eb8-
For API details, see RejectVpcPeeringConnection in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Disable-EC2VgwRoutePropagation.
- Tools for PowerShell V5
-
Example 1: This example disables the VGW from automatically propagating routes to the specified routing table.
Disable-EC2VgwRoutePropagation -RouteTableId rtb-12345678 -GatewayId vgw-1a2b3c4d-
For API details, see DisableVgwRoutePropagation in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Disable-EC2VpcClassicLink.
- Tools for PowerShell V5
-
Example 1: This example disables EC2VpcClassicLink for the vpc-01e23c4a5d6db78e9. It returns either True or False
Disable-EC2VpcClassicLink -VpcId vpc-01e23c4a5d6db78e9-
For API details, see DisableVpcClassicLink in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Disable-EC2VpcClassicLinkDnsSupport.
- Tools for PowerShell V5
-
Example 1: This example disables ClassicLink DNS support for the vpc-0b12d3456a7e8910d
Disable-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d-
For API details, see DisableVpcClassicLinkDnsSupport in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Dismount-EC2InternetGateway.
- Tools for PowerShell V5
-
Example 1: This example detaches the specified Internet gateway from the specified VPC.
Dismount-EC2InternetGateway -InternetGatewayId igw-1a2b3c4d -VpcId vpc-12345678-
For API details, see DetachInternetGateway in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Dismount-EC2NetworkInterface.
- Tools for PowerShell V5
-
Example 1: This example removes the specified attachment between a network interface and an instance.
Dismount-EC2NetworkInterface -AttachmentId eni-attach-1a2b3c4d -Force-
For API details, see DetachNetworkInterface in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Dismount-EC2Volume.
- Tools for PowerShell V5
-
Example 1: This example detaches the specified volume.
Dismount-EC2Volume -VolumeId vol-12345678Output:
AttachTime : 12/22/2015 1:53:58 AM DeleteOnTermination : False Device : /dev/sdh InstanceId : i-1a2b3c4d State : detaching VolumeId : vol-12345678Example 2: You can also specify the instance ID and device name to ensure that you are detaching the correct volume.
Dismount-EC2Volume -VolumeId vol-12345678 -InstanceId i-1a2b3c4d -Device /dev/sdh-
For API details, see DetachVolume in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Dismount-EC2VpnGateway.
- Tools for PowerShell V5
-
Example 1: This example detaches the specified virtual private gateway from the specified VPC.
Dismount-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678-
For API details, see DetachVpnGateway in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2CapacityReservation.
- Tools for PowerShell V5
-
Example 1: This example modifies the CapacityReservationId cr-0c1f2345db6f7cdba by changing the instane count to 1
Edit-EC2CapacityReservation -CapacityReservationId cr-0c1f2345db6f7cdba -InstanceCount 1Output:
True-
For API details, see ModifyCapacityReservation in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2Host.
- Tools for PowerShell V5
-
Example 1: This example modifies the AutoPlacement settings to off for the dedicated host h-01e23f4cd567890f3
Edit-EC2Host -HostId h-03e09f8cd681609f3 -AutoPlacement offOutput:
Successful Unsuccessful ---------- ------------ {h-01e23f4cd567890f3} {}-
For API details, see ModifyHosts in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2IdFormat.
- Tools for PowerShell V5
-
Example 1: This example enables the longer ID format for the specified resource type.
Edit-EC2IdFormat -Resource instance -UseLongId $trueExample 2: This example disables the longer ID format for the specified resource type.
Edit-EC2IdFormat -Resource instance -UseLongId $false-
For API details, see ModifyIdFormat in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2ImageAttribute.
- Tools for PowerShell V5
-
Example 1: This example updates the description for the specified AMI.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Description "New description"Example 2: This example makes the AMI public (for example, so any AWS account can use it).
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup allExample 3: This example makes the AMI private (for example, so that only you as the owner can use it).
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserGroup allExample 4: This example grants launch permission to the specified AWS account.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333Example 5: This example removes launch permission from the specified AWS account.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333-
For API details, see ModifyImageAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2InstanceAttribute.
- Tools for PowerShell V5
-
Example 1: This example modifies the instance type of the specified instance.
Edit-EC2InstanceAttribute -InstanceId i-12345678 -InstanceType m3.mediumExample 2: This example enables enhanced networking for the specified instance, by specifying "simple" as the value of the single root I/O virtualization (SR-IOV) network support parameter, -SriovNetSupport..
Edit-EC2InstanceAttribute -InstanceId i-12345678 -SriovNetSupport "simple"Example 3: This example modifies the security groups for the specified instance. The instance must be in a VPC. You must specify the ID of each security group, not the name.
Edit-EC2InstanceAttribute -InstanceId i-12345678 -Group @( "sg-12345678", "sg-45678901" )Example 4: This example enables EBS I/O optimization for the specified instance. This feature isn't available with all instance types. Additional usage charges apply when using an EBS-optimized instance.
Edit-EC2InstanceAttribute -InstanceId i-12345678 -EbsOptimized $trueExample 5: This example enables source/destination checking for the specified instance. For a NAT instance to perform NAT, the value must be 'false'.
Edit-EC2InstanceAttribute -InstanceId i-12345678 -SourceDestCheck $trueExample 6: This example disables termination for the specified instance.
Edit-EC2InstanceAttribute -InstanceId i-12345678 -DisableApiTermination $trueExample 7: This example changes the specified instance so that it terminates when shutdown is initiated from the instance.
Edit-EC2InstanceAttribute -InstanceId i-12345678 -InstanceInitiatedShutdownBehavior terminate-
For API details, see ModifyInstanceAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2InstanceCreditSpecification.
- Tools for PowerShell V5
-
Example 1: This enables T2 unlimited credits for instance i-01234567890abcdef.
$Credit = New-Object -TypeName Amazon.EC2.Model.InstanceCreditSpecificationRequest $Credit.InstanceId = "i-01234567890abcdef" $Credit.CpuCredits = "unlimited" Edit-EC2InstanceCreditSpecification -InstanceCreditSpecification $Credit-
For API details, see ModifyInstanceCreditSpecification in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2NetworkInterfaceAttribute.
- Tools for PowerShell V5
-
Example 1: This example modifies the specified network interface so that the specified attachment is deleted on termination.
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -Attachment_AttachmentId eni-attach-1a2b3c4d -Attachment_DeleteOnTermination $trueExample 2: This example modifies the description of the specified network interface.
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -Description "my description"Example 3: This example modifies the security group for the specified network interface.
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -Groups sg-1a2b3c4dExample 4: This example disables source/destination checking for the specified network interface.
Edit-EC2NetworkInterfaceAttribute -NetworkInterfaceId eni-1a2b3c4d -SourceDestCheck $false-
For API details, see ModifyNetworkInterfaceAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2ReservedInstance.
- Tools for PowerShell V5
-
Example 1: This example modifies the Availability Zone, instance count, and platform for the specified Reserved instances.
$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-
For API details, see ModifyReservedInstances in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2SnapshotAttribute.
- Tools for PowerShell V5
-
Example 1: This example makes the specified snapshot public by setting its CreateVolumePermission attribute.
Edit-EC2SnapshotAttribute -SnapshotId snap-12345678 -Attribute CreateVolumePermission -OperationType Add -GroupName all-
For API details, see ModifySnapshotAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2SpotFleetRequest.
- Tools for PowerShell V5
-
Example 1: This example updates the target capacity of the specified Spot fleet request.
Edit-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TargetCapacity 10Output:
True-
For API details, see ModifySpotFleetRequest in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2SubnetAttribute.
- Tools for PowerShell V5
-
Example 1: This example enables public IP addressing for the specified subnet.
Edit-EC2SubnetAttribute -SubnetId subnet-1a2b3c4d -MapPublicIpOnLaunch $trueExample 2: This example disables public IP addressing for the specified subnet.
Edit-EC2SubnetAttribute -SubnetId subnet-1a2b3c4d -MapPublicIpOnLaunch $false-
For API details, see ModifySubnetAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2VolumeAttribute.
- Tools for PowerShell V5
-
Example 1: This example modifies the specified attribute of the specified volume. I/O operations for the volume are automatically resumed after being suspended due to potentially inconsistent data.
Edit-EC2VolumeAttribute -VolumeId vol-12345678 -AutoEnableIO $true-
For API details, see ModifyVolumeAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Edit-EC2VpcAttribute.
- Tools for PowerShell V5
-
Example 1: This example enables support for DNS hostnames for the specified VPC.
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsHostnames $trueExample 2: This example disables support for DNS hostnames for the specified VPC.
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsHostnames $falseExample 3: This example enables support for DNS resolution for the specified VPC.
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsSupport $trueExample 4: This example disables support for DNS resolution for the specified VPC.
Edit-EC2VpcAttribute -VpcId vpc-12345678 -EnableDnsSupport $false-
For API details, see ModifyVpcAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Enable-EC2VgwRoutePropagation.
- Tools for PowerShell V5
-
Example 1: This example enables the specified VGW to propagate routes automatically to the specified routing table.
Enable-EC2VgwRoutePropagation -RouteTableId rtb-12345678 -GatewayId vgw-1a2b3c4d-
For API details, see EnableVgwRoutePropagation in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Enable-EC2VolumeIO.
- Tools for PowerShell V5
-
Example 1: This example enables I/O operations for the specified volume, if I/O operations were disabled.
Enable-EC2VolumeIO -VolumeId vol-12345678-
For API details, see EnableVolumeIo in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Enable-EC2VpcClassicLink.
- Tools for PowerShell V5
-
Example 1: This example enables VPC vpc-0123456b789b0d12f for ClassicLink
Enable-EC2VpcClassicLink -VpcId vpc-0123456b789b0d12fOutput:
True-
For API details, see EnableVpcClassicLink in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Enable-EC2VpcClassicLinkDnsSupport.
- Tools for PowerShell V5
-
Example 1: This example enables vpc-0b12d3456a7e8910d to support DNS hostname resolution for ClassicLink
Enable-EC2VpcClassicLinkDnsSupport -VpcId vpc-0b12d3456a7e8910d -Region eu-west-1-
For API details, see EnableVpcClassicLinkDnsSupport in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2AccountAttribute.
- Tools for PowerShell V5
-
Example 1: This example describes whether you can launch instances into EC2-Classic and EC2-VPC in the region, or only into EC2-VPC.
(Get-EC2AccountAttribute -AttributeName supported-platforms).AttributeValuesOutput:
AttributeValue -------------- EC2 VPCExample 2: This example describes your default VPC, or is 'none' if you do not have a default VPC in the region.
(Get-EC2AccountAttribute -AttributeName default-vpc).AttributeValuesOutput:
AttributeValue -------------- vpc-12345678Example 3: This example describes the maximum number of On-Demand instances that you can run.
(Get-EC2AccountAttribute -AttributeName max-instances).AttributeValuesOutput:
AttributeValue -------------- 20-
For API details, see DescribeAccountAttributes in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2Address.
- Tools for PowerShell V5
-
Example 1: This example describes the specified Elastic IP address for instances in EC2-Classic.
Get-EC2Address -AllocationId eipalloc-12345678Output:
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.2Example 2: This example describes your Elastic IP addresses for instances in a VPC. This syntax requires PowerShell version 3 or later.
Get-EC2Address -Filter @{ Name="domain";Values="vpc" }Example 3: This example describes the specified Elastic IP address for instances in EC2-Classic.
Get-EC2Address -PublicIp 203.0.113.17Output:
AllocationId : AssociationId : Domain : standard InstanceId : i-12345678 NetworkInterfaceId : NetworkInterfaceOwnerId : PrivateIpAddress : PublicIp : 203.0.113.17Example 4: This example describes your Elastic IP addresses for instances in EC2-Classic. This syntax requires PowerShell version 3 or later.
Get-EC2Address -Filter @{ Name="domain";Values="standard" }Example 5: This example describes all your Elastic IP addresses.
Get-EC2AddressExample 6: This example returns the public and private IP for the instance id provided in filter
Get-EC2Address -Region eu-west-1 -Filter @{Name="instance-id";Values="i-0c12d3f4f567ffb89"} | Select-Object PrivateIpAddress, PublicIpOutput:
PrivateIpAddress PublicIp ---------------- -------- 10.0.0.99 63.36.5.227Example 7: This example retrieves all the Elastic IPs with its allocation id, association id and instance ids
Get-EC2Address -Region eu-west-1 | Select-Object InstanceId, AssociationId, AllocationId, PublicIpOutput:
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.270Example 8: This example fetches list of EC2 IP addresses matching tag key 'Category' with value 'Prod'
Get-EC2Address -Filter @{Name="tag:Category";Values="Prod"}Output:
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}-
For API details, see DescribeAddresses in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2AvailabilityZone.
- Tools for PowerShell V5
-
Example 1: This example describes the Availability Zones for the current region that are available to you.
Get-EC2AvailabilityZoneOutput:
Messages RegionName State ZoneName -------- ---------- ----- -------- {} us-west-2 available us-west-2a {} us-west-2 available us-west-2b {} us-west-2 available us-west-2cExample 2: This example describes any Availability Zones that are in an impaired state. The syntax used by this example requires PowerShell version 3 or higher.
Get-EC2AvailabilityZone -Filter @{ Name="state";Values="impaired" }Example 3: With PowerShell version 2, you must use New-Object to create the filter.
$filter = New-Object Amazon.EC2.Model.Filter $filter.Name = "state" $filter.Values = "impaired" Get-EC2AvailabilityZone -Filter $filter-
For API details, see DescribeAvailabilityZones in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2BundleTask.
- Tools for PowerShell V5
-
Example 1: This example describes the specified bundle task.
Get-EC2BundleTask -BundleId bun-12345678Example 2: This example describes the bundle tasks whose state is either 'complete' or 'failed'.
$filter = New-Object Amazon.EC2.Model.Filter $filter.Name = "state" $filter.Values = @( "complete", "failed" ) Get-EC2BundleTask -Filter $filter-
For API details, see DescribeBundleTasks in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2CapacityReservation.
- Tools for PowerShell V5
-
Example 1: This example describes one or more of your Capacity Reservations for the region
Get-EC2CapacityReservation -Region eu-west-1Output:
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-
For API details, see DescribeCapacityReservations in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2ConsoleOutput.
- Tools for PowerShell V5
-
Example 1: This example gets the console output for the specified Linux instance. The console output is encoded.
Get-EC2ConsoleOutput -InstanceId i-0e19abcd47c123456Output:
InstanceId Output ---------- ------ i-0e194d3c47c123637 WyAgICAwLjAwMDAwMF0gQ29tbW...bGU9dHR5UzAgc2VsExample 2: This example stores the encoded console output in a variable and then decodes it.
$Output_encoded = (Get-EC2ConsoleOutput -InstanceId i-0e19abcd47c123456).Output [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Output_encoded))-
For API details, see GetConsoleOutput in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2CustomerGateway.
- Tools for PowerShell V5
-
Example 1: This example describes the specified customer gateway.
Get-EC2CustomerGateway -CustomerGatewayId cgw-1a2b3c4dOutput:
BgpAsn : 65534 CustomerGatewayId : cgw-1a2b3c4d IpAddress : 203.0.113.12 State : available Tags : {} Type : ipsec.1Example 2: This example describes any customer gateway whose state is either pending or available.
$filter = New-Object Amazon.EC2.Model.Filter $filter.Name = "state" $filter.Values = @( "pending", "available" ) Get-EC2CustomerGateway -Filter $filterExample 3: This example describes all your customer gateways.
Get-EC2CustomerGateway-
For API details, see DescribeCustomerGateways in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-EC2DhcpOption.