

There are more AWS SDK examples available in the [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) GitHub repo.

# Use `DeregisterTargets` with a CLI
<a name="elastic-load-balancing-v2_example_elastic-load-balancing-v2_DeregisterTargets_section"></a>

The following code examples show how to use `DeregisterTargets`.

------
#### [ CLI ]

**AWS CLI**  
**Example 1: To deregister a target from a target group**  
The following `deregister-targets` example removes the specified instance from the specified target group.  

```
aws elbv2 deregister-targets \
    --target-group-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067}} \
    --targets {{Id=i-1234567890abcdef0}}
```
**Example 2: To deregister a target registered using port overrides**  
The following `deregister-targets` example removes an instance from a target group that was registered using port overrides.  

```
aws elbv2 deregister-targets \
    --target-group-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-internal-targets/3bb63f11dfb0faf9}} \
    --targets {{Id=i-1234567890abcdef0,Port=80}} {{Id=i-1234567890abcdef0,Port=766}}
```
+  For API details, see [DeregisterTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/elbv2/deregister-targets.html) in *AWS CLI Command Reference*. 

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**Example 1: This example deregisters instance 'i-0672a4c4cdeae3111' from the specified Target group.**  

```
$targetDescription = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$targetDescription.Id = 'i-0672a4c4cdeae3111'
Unregister-ELB2Target -Target $targetDescription -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970'
```
+  For API details, see [DeregisterTargets](https://docs.aws.amazon.com/powershell/v4/reference) in *AWS Tools for PowerShell Cmdlet Reference (V4)*. 

**Tools for PowerShell V5**  
**Example 1: This example deregisters instance 'i-0672a4c4cdeae3111' from the specified Target group.**  

```
$targetDescription = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$targetDescription.Id = 'i-0672a4c4cdeae3111'
Unregister-ELB2Target -Target $targetDescription -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970'
```
+  For API details, see [DeregisterTargets](https://docs.aws.amazon.com/powershell/v5/reference) in *AWS Tools for PowerShell Cmdlet Reference (V5)*. 

------