

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# 搭配使用 `RegisterInstancesWithLoadBalancer` 與 CLI
<a name="elastic-load-balancing_example_elastic-load-balancing_RegisterInstancesWithLoadBalancer_section"></a>

下列程式碼範例示範如何使用 `RegisterInstancesWithLoadBalancer`。

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

**AWS CLI**  
**將負載平衡器註冊到執行個體**  
此範例會將指定的負載平衡器註冊到指定的執行個體。  
命令：  

```
aws elb register-instances-with-load-balancer --load-balancer-name my-load-balancer --instances i-d6f6fae3
```
輸出：  

```
{
   "Instances": [
       {
           "InstanceId": "i-d6f6fae3"
       },
       {
           "InstanceId": "i-207d9717"
       },
       {
           "InstanceId": "i-afefb49b"
       }
   ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [RegisterInstancesWithLoadBalancer](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/elb/register-instances-with-load-balancer.html)。

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

**Tools for PowerShell V4**  
**範例 1：此範例會向指定的負載平衡器註冊指定的 EC2 執行個體。**  

```
Register-ELBInstanceWithLoadBalancer -LoadBalancerName my-load-balancer -Instance i-12345678
```
**輸出：**  

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

**Tools for PowerShell V5**  
**範例 1：此範例會向指定的負載平衡器註冊指定的 EC2 執行個體。**  

```
Register-ELBInstanceWithLoadBalancer -LoadBalancerName my-load-balancer -Instance i-12345678
```
**輸出：**  

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

------