

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

# 使用 的組織範例 AWS CLI
<a name="cli_organizations_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Organizations 執行動作和實作常見案例。

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

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

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

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

### `accept-handshake`
<a name="organizations_AcceptHandshake_cli_topic"></a>

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

**AWS CLI**  
**接受來自另一個帳戶的交握**  
組織機構的創辦人 Bill 先前已邀請 Juan 的帳戶加入他的組織。下列範例顯示 Juan 的帳戶接受交握，因此同意邀請。  

```
aws organizations accept-handshake --handshake-id h-examplehandshakeid111
```
輸出會顯示下列內容：  

```
{
        "Handshake": {
                "Action": "INVITE",
                "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111",
                "RequestedTimestamp": 1481656459.257,
                "ExpirationTimestamp": 1482952459.257,
                "Id": "h-examplehandshakeid111",
                "Parties": [
                        {
                                "Id": "o-exampleorgid",
                                "Type": "ORGANIZATION"
                        },
                        {
                                "Id": "juan@example.com",
                                "Type": "EMAIL"
                        }
                ],
                "Resources": [
                        {
                                "Resources": [
                                        {
                                                "Type": "MASTER_EMAIL",
                                                "Value": "bill@amazon.com"
                                        },
                                        {
                                                "Type": "MASTER_NAME",
                                                "Value": "Org Master Account"
                                        },
                                        {
                                                "Type": "ORGANIZATION_FEATURE_SET",
                                                "Value": "ALL"
                                        }
                                ],
                                "Type": "ORGANIZATION",
                                "Value": "o-exampleorgid"
                        },
                        {
                                "Type": "EMAIL",
                                "Value": "juan@example.com"
                        }
                ],
                "State": "ACCEPTED"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [AcceptHandshake](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/accept-handshake.html)。

### `attach-policy`
<a name="organizations_AttachPolicy_cli_topic"></a>

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

**AWS CLI**  
**將政策連接到根帳戶、OU 或帳戶**  
**範例 1**  
下列範例示範如何將服務控制政策 (SCP) 連接至 OU：  

```
aws organizations attach-policy
                --policy-id p-examplepolicyid111
                --target-id ou-examplerootid111-exampleouid111
```
**範例 2**  
下列範例示範如何將服務控制政策直接連接至帳戶：  

```
aws organizations attach-policy
                --policy-id p-examplepolicyid111
                --target-id 333333333333
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [AttachPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/attach-policy.html)。

### `cancel-handshake`
<a name="organizations_CancelHandshake_cli_topic"></a>

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

**AWS CLI**  
**取消從另一個帳戶傳送的交握**  
Bill 先前傳送邀請給 Susan 的帳戶加入他的組織。他改變主意，決定在 Susan 接受邀請之前取消邀請。下列範例顯示 Bill 的取消：  

```
aws organizations cancel-handshake --handshake-id h-examplehandshakeid111
```
輸出包含交握物件，顯示狀態現在為 `CANCELED`：  

```
{
        "Handshake": {
                "Id": "h-examplehandshakeid111",
                "State":"CANCELED",
                "Action": "INVITE",
                "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111",
                "Parties": [
                        {
                                "Id": "o-exampleorgid",
                                "Type": "ORGANIZATION"
                        },
                        {
                                "Id": "susan@example.com",
                                "Type": "EMAIL"
                        }
                ],
                "Resources": [
                        {
                                "Type": "ORGANIZATION",
                                "Value": "o-exampleorgid",
                                "Resources": [
                                        {
                                                "Type": "MASTER_EMAIL",
                                                "Value": "bill@example.com"
                                        },
                                        {
                                                "Type": "MASTER_NAME",
                                                "Value": "Master Account"
                                        },
                                        {
                                                "Type": "ORGANIZATION_FEATURE_SET",
                                                "Value": "CONSOLIDATED_BILLING"
                                        }
                                ]
                        },
                        {
                                "Type": "EMAIL",
                                "Value": "anika@example.com"
                        },
                        {
                                "Type": "NOTES",
                                "Value": "This is a request for Susan's account to join Bob's organization."
                        }
                ],
                "RequestedTimestamp": 1.47008383521E9,
                "ExpirationTimestamp": 1.47137983521E9
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CancelHandshake](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/cancel-handshake.html)。

### `create-account`
<a name="organizations_CreateAccount_cli_topic"></a>

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

**AWS CLI**  
**建立會自動成為組織一部分的成員帳戶**  
下列範例示範如何在組織中建立成員帳戶。成員帳戶是以生產帳戶名稱和 susan@example.com 的電子郵件地址來設定。Organizations 會使用 OrganizationAccountAccessRole 的預設名稱自動建立 IAM 角色，因為未指定 roleName 參數。此外，由於未指定 IamUserAccessToBilling 參數，因此允許具有足夠許可存取帳戶帳單資料的 IAM 使用者或角色的設定會設定為預設值 ALLOW。Organizations 會自動傳送「歡迎 AWS」電子郵件給 Susan：  

```
aws organizations create-account --email susan@example.com --account-name "Production Account"
```
輸出包含一個請求物件，顯示狀態現在為 `IN_PROGRESS`：  

```
{
        "CreateAccountStatus": {
                "State": "IN_PROGRESS",
                "Id": "car-examplecreateaccountrequestid111"
        }
}
```
您稍後可以將 Id 回應值作為 create-account-request-id 參數的值提供給 describe-create-account-status 命令，以查詢請求的目前狀態。  
如需詳細資訊，請參閱《 *AWS Organizations 使用者指南*》中的在您的組織中建立 AWS 帳戶。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/create-account.html)。

### `create-organization`
<a name="organizations_CreateOrganization_cli_topic"></a>

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

**AWS CLI**  
**範例 1：建立新組織**  
Bill 想要使用帳戶 111111111111 的憑證來建立組織。下列範例顯示帳戶成為新組織中的主要帳戶。由於他未指定功能集，因此新組織會預設為啟用所有功能，並在根帳戶上啟用服務控制政策。  

```
aws organizations create-organization
```
輸出包含一個組織物件，其中包含新組織的詳細資訊：  

```
{
        "Organization": {
                "AvailablePolicyTypes": [
                        {
                                "Status": "ENABLED",
                                "Type": "SERVICE_CONTROL_POLICY"
                        }
                ],
                "MasterAccountId": "111111111111",
                "MasterAccountArn": "arn:aws:organizations::111111111111:account/o-exampleorgid/111111111111",
                "MasterAccountEmail": "bill@example.com",
                "FeatureSet": "ALL",
                "Id": "o-exampleorgid",
                "Arn": "arn:aws:organizations::111111111111:organization/o-exampleorgid"
        }
}
```
**範例 2：建立僅啟用合併帳單功能的新組織**  
下列範例會建立僅支援合併帳單功能的組織：  

```
aws organizations create-organization --feature-set CONSOLIDATED_BILLING
```
輸出包含一個組織物件，其中包含新組織的詳細資訊：  

```
{
        "Organization": {
                "Arn": "arn:aws:organizations::111111111111:organization/o-exampleorgid",
                "AvailablePolicyTypes": [],
                "Id": "o-exampleorgid",
                "MasterAccountArn": "arn:aws:organizations::111111111111:account/o-exampleorgid/111111111111",
                "MasterAccountEmail": "bill@example.com",
                "MasterAccountId": "111111111111",
                "FeatureSet": "CONSOLIDATED_BILLING"
        }
}
```
如需詳細資訊，請參閱《AWS Organizations 使用者指南》**中的建立組織。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/create-organization.html)。

### `create-organizational-unit`
<a name="organizations_CreateOrganizationalUnit_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-organizational-unit`。

**AWS CLI**  
**在根或父 OU 中建立 OU**  
下列範例示範如何建立名為 AccountingOU 的 OU：  

```
aws organizations create-organizational-unit --parent-id r-examplerootid111 --name AccountingOU
```
輸出包含 organizationalUnit 物件，其中包含新 OU 的詳細資訊：  

```
{
        "OrganizationalUnit": {
                "Id": "ou-examplerootid111-exampleouid111",
                "Arn": "arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111",
                "Name": "AccountingOU"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateOrganizationalUnit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/create-organizational-unit.html)。

### `create-policy`
<a name="organizations_CreatePolicy_cli_topic"></a>

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

**AWS CLI**  
**範例 1：使用 JSON 政策的文字來源檔案建立政策**  
下列範例示範如何建立名為 `AllowAllS3Actions` 的服務控制政策 (SCP)。政策內容取自本機電腦上名為 `policy.json` 的檔案。  

```
aws organizations create-policy --content file://policy.json --name AllowAllS3Actions, --type SERVICE_CONTROL_POLICY --description "Allows delegation of all S3 actions"
```
輸出包含政策物件，其中包含新政策的詳細資訊：  

```
{
        "Policy": {
                "Content": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"*\"]}]}",
                "PolicySummary": {
                        "Arn": "arn:aws:organizations::o-exampleorgid:policy/service_control_policy/p-examplepolicyid111",
                        "Description": "Allows delegation of all S3 actions",
                        "Name": "AllowAllS3Actions",
                        "Type":"SERVICE_CONTROL_POLICY"
                }
        }
}
```
**範例 2：使用 JSON 政策作為參數來建立政策**  
下列範例示範如何建立相同的 SCP，這次在參數中將政策內容嵌入為 JSON 字串。字串必須在雙引號之前以反斜線逸出，以確保它們在參數中被視為常值，而其本身被雙引號包圍：  

```
aws organizations create-policy --content "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"*\"]}]}" --name AllowAllS3Actions --type SERVICE_CONTROL_POLICY --description "Allows delegation of all S3 actions"
```
如需在組織中建立和使用政策的詳細資訊，請參閱《AWS Organizations 使用者指南》**中的管理組織政策。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreatePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/create-policy.html)。

### `decline-handshake`
<a name="organizations_DeclineHandshake_cli_topic"></a>

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

**AWS CLI**  
**拒絕從另一個帳戶傳送的交握**  
下列範例顯示身為帳戶 222222222222 擁有者的管理員 Susan 拒絕加入 Bill 組織的邀請。DeclineHandshake 操作會傳回交握物件，顯示狀態現在為 DECLINED：  

```
aws organizations decline-handshake --handshake-id h-examplehandshakeid111
```
輸出包含一個交握物件，顯示 `DECLINED` 的新狀態：  

```
{
        "Handshake": {
                "Id": "h-examplehandshakeid111",
                "State": "DECLINED",
                "Resources": [
                        {
                                "Type": "ORGANIZATION",
                                "Value": "o-exampleorgid",
                                "Resources": [
                                        {
                                                "Type": "MASTER_EMAIL",
                                                "Value": "bill@example.com"
                                        },
                                        {
                                                "Type": "MASTER_NAME",
                                                "Value": "Master Account"
                                        }
                                ]
                        },
                        {
                                "Type": "EMAIL",
                                "Value": "susan@example.com"
                        },
                        {
                                "Type": "NOTES",
                                "Value": "This is an invitation to Susan's account to join the Bill's organization."
                        }
                ],
                "Parties": [
                        {
                                "Type": "EMAIL",
                                "Id": "susan@example.com"
                        },
                        {
                                "Type": "ORGANIZATION",
                                "Id": "o-exampleorgid"
                        }
                ],
                "Action": "INVITE",
                "RequestedTimestamp": 1470684478.687,
                "ExpirationTimestamp": 1471980478.687,
                "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeclineHandshake](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/decline-handshake.html)。

### `delete-organization`
<a name="organizations_DeleteOrganization_cli_topic"></a>

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

**AWS CLI**  
**刪除組織**  
下列範例顯示如何刪除組織。若要執行此操作，您必須是組織中主帳戶的管理員。此範例假設您先前已從組織移除所有成員帳戶、OU 和政策：  

```
aws organizations delete-organization
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/delete-organization.html)。

### `delete-organizational-unit`
<a name="organizations_DeleteOrganizationalUnit_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-organizational-unit`。

**AWS CLI**  
**刪除 OU**  
下列範例顯示如何刪除 OU。此範例假設您先前已從 OU 移除所有帳戶和其他 OU：  

```
aws organizations delete-organizational-unit --organizational-unit-id ou-examplerootid111-exampleouid111
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteOrganizationalUnit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/delete-organizational-unit.html)。

### `delete-policy`
<a name="organizations_DeletePolicy_cli_topic"></a>

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

**AWS CLI**  
**刪除政策**  
下列範例示範如何從組織刪除政策。此範例假設您先前已從所有實體分開政策：  

```
aws organizations delete-policy --policy-id p-examplepolicyid111
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeletePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/delete-policy.html)。

### `describe-account`
<a name="organizations_DescribeAccount_cli_topic"></a>

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

**AWS CLI**  
**取得帳戶的詳細資訊**  
下列範例示範如何請求帳戶的詳細資訊。  

```
aws organizations describe-account --account-id 555555555555
```
輸出會顯示帳戶物件，其中包含帳戶的詳細資訊：  

```
{
        "Account": {
                "Id": "555555555555",
                "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/555555555555",
                "Name": "Beta account",
                "Email": "anika@example.com",
                "JoinedMethod": "INVITED",
                "JoinedTimeStamp": 1481756563.134,
                "Status": "ACTIVE"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-account.html)。

### `describe-create-account-status`
<a name="organizations_DescribeCreateAccountStatus_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-create-account-status`。

**AWS CLI**  
**若要取得建立帳戶之請求的最新狀態**  
下列範例顯示如何請求先前請求的最新狀態，以在組織中建立帳戶。指定的 --request-id 來自原始呼叫 create-account 的回應。帳戶建立請求會顯示 Organizations 成功完成帳戶建立的狀態欄位。  
命令：  

```
aws organizations describe-create-account-status --create-account-request-id car-examplecreateaccountrequestid111
```
輸出：  

```
{
  "CreateAccountStatus": {
    "State": "SUCCEEDED",
    "AccountId": "555555555555",
    "AccountName": "Beta account",
    "RequestedTimestamp": 1470684478.687,
    "CompletedTimestamp": 1470684532.472,
    "Id": "car-examplecreateaccountrequestid111"
  }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeCreateAccountStatus](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-create-account-status.html)。

### `describe-handshake`
<a name="organizations_DescribeHandshake_cli_topic"></a>

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

**AWS CLI**  
**取得交握的詳細資訊**  
下列範例示範如何請求有關交握的詳細資訊。交握 ID 來自對 `InviteAccountToOrganization` 的原始呼叫，或來自對 `ListHandshakesForAccount` 或 `ListHandshakesForOrganization` 的呼叫：  

```
aws organizations describe-handshake --handshake-id h-examplehandshakeid111
```
輸出包含交握物件，其中包含請求交握的所有詳細資訊：  

```
{
        "Handshake": {
                "Id": "h-examplehandshakeid111",
                "State": "OPEN",
                "Resources": [
                        {
                                "Type": "ORGANIZATION",
                                "Value": "o-exampleorgid",
                                "Resources": [
                                        {
                                                "Type": "MASTER_EMAIL",
                                                "Value": "bill@example.com"
                                        },
                                        {
                                                "Type": "MASTER_NAME",
                                                "Value": "Master Account"
                                        }
                                ]
                        },
                        {
                                "Type": "EMAIL",
                                "Value": "anika@example.com"
                        }
                ],
                "Parties": [
                        {
                                "Type": "ORGANIZATION",
                                "Id": "o-exampleorgid"
                        },
                        {
                                "Type": "EMAIL",
                                "Id": "anika@example.com"
                        }
                ],
                "Action": "INVITE",
                "RequestedTimestamp": 1470158698.046,
                "ExpirationTimestamp": 1471454698.046,
                "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeHandshake](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-handshake.html)。

### `describe-organization`
<a name="organizations_DescribeOrganization_cli_topic"></a>

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

**AWS CLI**  
**取得目前組織的相關資訊**  
下列範例示範如何請求有關組織的詳細資訊：  

```
aws organizations describe-organization
```
輸出包含具有組織詳細資訊的組織物件：  

```
{
        "Organization": {
                "MasterAccountArn": "arn:aws:organizations::111111111111:account/o-exampleorgid/111111111111",
                "MasterAccountEmail": "bill@example.com",
                "MasterAccountId": "111111111111",
                "Id": "o-exampleorgid",
                "FeatureSet": "ALL",
                "Arn": "arn:aws:organizations::111111111111:organization/o-exampleorgid",
                "AvailablePolicyTypes": [
                        {
                                "Status": "ENABLED",
                                "Type": "SERVICE_CONTROL_POLICY"
                        }
                ]
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-organization.html)。

### `describe-organizational-unit`
<a name="organizations_DescribeOrganizationalUnit_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-organizational-unit`。

**AWS CLI**  
**取得 OU 的相關資訊**  
下列 `describe-organizational-unit` 範例會請求有關 OU 的詳細資訊。  

```
aws organizations describe-organizational-unit \
    --organizational-unit-id ou-examplerootid111-exampleouid111
```
輸出：  

```
{
    "OrganizationalUnit": {
        "Name": "Accounting Group",
        "Arn": "arn:aws:organizations::123456789012:ou/o-exampleorgid/ou-examplerootid111-exampleouid111",
        "Id": "ou-examplerootid111-exampleouid111"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeOrganizationalUnit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-organizational-unit.html)。

### `describe-policy`
<a name="organizations_DescribePolicy_cli_topic"></a>

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

**AWS CLI**  
**取得政策的相關資訊**  
下列範例示範如何請求政策的相關資訊：  

```
aws organizations describe-policy --policy-id p-examplepolicyid111
```
輸出包含政策物件，其中包含政策的詳細資訊：  

```
{
        "Policy": {
                "Content": "{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": \"*\",\n      \"Resource\": \"*\"\n    }\n  ]\n}",
                "PolicySummary": {
                        "Arn": "arn:aws:organizations::111111111111:policy/o-exampleorgid/service_control_policy/p-examplepolicyid111",
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Id": "p-examplepolicyid111",
                        "AwsManaged": false,
                        "Name": "AllowAllS3Actions",
                        "Description": "Enables admins to delegate S3 permissions"
                }
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-policy.html)。

### `detach-policy`
<a name="organizations_DetachPolicy_cli_topic"></a>

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

**AWS CLI**  
**將政策從根帳戶、OU 或帳戶分開**  
下列範例示範如何從 OU 分開政策。  

```
aws organizations  detach-policy  --target-id ou-examplerootid111-exampleouid111 --policy-id p-examplepolicyid111
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DetachPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/detach-policy.html)。

### `disable-policy-type`
<a name="organizations_DisablePolicyType_cli_topic"></a>

以下程式碼範例顯示如何使用 `disable-policy-type`。

**AWS CLI**  
**在根帳戶中停用政策類型**  
下列範例顯示如何在根帳戶中停用服務控制政策 (SCP) 政策類型：  

```
aws organizations disable-policy-type --root-id r-examplerootid111 --policy-type SERVICE_CONTROL_POLICY
```
輸出顯示 PolicyTypes 回應元素不再包含 SERVICE\$1CONTROL\$1POLICY：  

```
{
        "Root": {
                "PolicyTypes": [],
                "Name": "Root",
                "Id": "r-examplerootid111",
                "Arn": "arn:aws:organizations::111111111111:root/o-exampleorgid/r-examplerootid111"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DisablePolicyType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/disable-policy-type.html)。

### `enable-all-features`
<a name="organizations_EnableAllFeatures_cli_topic"></a>

以下程式碼範例顯示如何使用 `enable-all-features`。

**AWS CLI**  
**啟用組織中的所有功能**  
此範例顯示管理員要求組織中的所有受邀帳戶核准組織中已啟用的所有功能。 AWS 組織會傳送電子郵件到向每個受邀成員帳戶註冊的地址，要求擁有者透過接受傳送的交握來核准所有功能的變更。在所有獲邀請的成員帳戶接受交握後，組織管理員可以完成所有功能的變更，而具有適當許可的人員可以建立政策並將其套用至根帳戶、OU 和帳戶：  

```
aws organizations enable-all-features
```
輸出是交握物件，會傳送至所有受邀成員帳戶進行核准：  

```
{
        "Handshake": {
                "Action": "ENABLE_ALL_FEATURES",
                "Arn":"arn:aws:organizations::111111111111:handshake/o-exampleorgid/enable_all_features/h-examplehandshakeid111",
                "ExpirationTimestamp":1.483127868609E9,
                "Id":"h-examplehandshakeid111",
                "Parties": [
                        {
                                "id":"o-exampleorgid",
                                "type":"ORGANIZATION"
                        }
                ],
                "requestedTimestamp":1.481831868609E9,
                "resources": [
                        {
                                "type":"ORGANIZATION",
                                "value":"o-exampleorgid"
                        }
                ],
                "state":"REQUESTED"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [EnableAllFeatures](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/enable-all-features.html)。

### `enable-policy-type`
<a name="organizations_EnablePolicyType_cli_topic"></a>

以下程式碼範例顯示如何使用 `enable-policy-type`。

**AWS CLI**  
**在根帳戶中啟用政策類型的使用**  
下列範例顯示如何在根中啟用服務控制政策 (SCP) 政策類型：  

```
aws organizations enable-policy-type --root-id r-examplerootid111 --policy-type SERVICE_CONTROL_POLICY
```
輸出顯示具有 policyTypes 回應元素的根物件，表示現在已啟用 SCP：  

```
{
        "Root": {
                "PolicyTypes": [
                        {
                                "Status":"ENABLED",
                                "Type":"SERVICE_CONTROL_POLICY"
                        }
                ],
                "Id": "r-examplerootid111",
                "Name": "Root",
                "Arn": "arn:aws:organizations::111111111111:root/o-exampleorgid/r-examplerootid111"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [EnablePolicyType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/enable-policy-type.html)。

### `invite-account-to-organization`
<a name="organizations_InviteAccountToOrganization_cli_topic"></a>

以下程式碼範例顯示如何使用 `invite-account-to-organization`。

**AWS CLI**  
**邀請帳戶加入組織**  
以下範例顯示 bill@example.com 擁有的主帳戶邀請 juan@example.com 擁有的帳戶加入組織：  

```
aws organizations invite-account-to-organization --target '{"Type": "EMAIL", "Id": "juan@example.com"}' --notes "This is a request for Juan's account to join Bill's organization."
```
輸出包含交握結構，顯示傳送至受邀帳戶的內容：  

```
{
        "Handshake": {
                "Action": "INVITE",
                "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111",
                "ExpirationTimestamp": 1482952459.257,
                "Id": "h-examplehandshakeid111",
                "Parties": [
                        {
                                "Id": "o-exampleorgid",
                                "Type": "ORGANIZATION"
                        },
                        {
                                "Id": "juan@example.com",
                                "Type": "EMAIL"
                        }
                ],
                "RequestedTimestamp": 1481656459.257,
                "Resources": [
                        {
                                "Resources": [
                                        {
                                                "Type": "MASTER_EMAIL",
                                                "Value": "bill@amazon.com"
                                        },
                                        {
                                                "Type": "MASTER_NAME",
                                                "Value": "Org Master Account"
                                        },
                                        {
                                                "Type": "ORGANIZATION_FEATURE_SET",
                                                "Value": "FULL"
                                        }
                                ],
                                "Type": "ORGANIZATION",
                                "Value": "o-exampleorgid"
                        },
                        {
                                "Type": "EMAIL",
                                "Value": "juan@example.com"
                        }
                ],
                "State": "OPEN"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [InviteAccountToOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/invite-account-to-organization.html)。

### `leave-organization`
<a name="organizations_LeaveOrganization_cli_topic"></a>

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

**AWS CLI**  
**以會員帳戶的身分離開組織**  
下列範例顯示請求離開組織的成員帳戶的管理員，目前成員屬於：  

```
aws organizations leave-organization
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [LeaveOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/leave-organization.html)。

### `list-accounts-for-parent`
<a name="organizations_ListAccountsForParent_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-accounts-for-parent`。

**AWS CLI**  
**擷取指定父根帳戶或 OU 中所有帳戶的清單**  
下列範例顯示如何請求 OU 中的帳戶清單：  

```
aws organizations list-accounts-for-parent --parent-id ou-examplerootid111-exampleouid111
```
輸出包含帳戶摘要物件的清單。  

```
{
        "Accounts": [
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/333333333333",
                        "JoinedMethod": "INVITED",
                        "JoinedTimestamp": 1481835795.536,
                        "Id": "333333333333",
                        "Name": "Development Account",
                        "Email": "juan@example.com",
                        "Status": "ACTIVE"
                },
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/444444444444",
                        "JoinedMethod": "INVITED",
                        "JoinedTimestamp": 1481835812.143,
                        "Id": "444444444444",
                        "Name": "Test Account",
                        "Email": "anika@example.com",
                        "Status": "ACTIVE"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListAccountsForParent](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-accounts-for-parent.html)。

### `list-accounts`
<a name="organizations_ListAccounts_cli_topic"></a>

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

**AWS CLI**  
**擷取組織中所有帳戶的清單**  
下列範例示範如何請求組織中的帳戶清單：  

```
aws organizations list-accounts
```
輸出包含帳戶摘要物件的清單。  

```
{
        "Accounts": [
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/111111111111",
                        "JoinedMethod": "INVITED",
                        "JoinedTimestamp": 1481830215.45,
                        "Id": "111111111111",
                        "Name": "Master Account",
                        "Email": "bill@example.com",
                        "Status": "ACTIVE"
                },
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/222222222222",
                        "JoinedMethod": "INVITED",
                        "JoinedTimestamp": 1481835741.044,
                        "Id": "222222222222",
                        "Name": "Production Account",
                        "Email": "alice@example.com",
                        "Status": "ACTIVE"
                },
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/333333333333",
                        "JoinedMethod": "INVITED",
                        "JoinedTimestamp": 1481835795.536,
                        "Id": "333333333333",
                        "Name": "Development Account",
                        "Email": "juan@example.com",
                        "Status": "ACTIVE"
                },
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/444444444444",
                        "JoinedMethod": "INVITED",
                        "JoinedTimestamp": 1481835812.143,
                        "Id": "444444444444",
                        "Name": "Test Account",
                        "Email": "anika@example.com",
                        "Status": "ACTIVE"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListAccounts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-accounts.html)。

### `list-children`
<a name="organizations_ListChildren_cli_topic"></a>

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

**AWS CLI**  
**擷取父 OU 或根帳戶的子帳戶和 OU**  
下列範例說明如何列出包含該帳戶 444444444444 的根帳戶或 OU：  

```
aws organizations list-children --child-type ORGANIZATIONAL_UNIT --parent-id ou-examplerootid111-exampleouid111
```
輸出會顯示父系包含的兩個子 OU：  

```
{
        "Children": [
                {
                        "Id": "ou-examplerootid111-exampleouid111",
                        "Type":"ORGANIZATIONAL_UNIT"
                },
                {
                        "Id":"ou-examplerootid111-exampleouid222",
                        "Type":"ORGANIZATIONAL_UNIT"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListChildren](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-children.html)。

### `list-create-account-status`
<a name="organizations_ListCreateAccountStatus_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-create-account-status`。

**AWS CLI**  
**範例 1：擷取目前組織中提出的帳戶建立請求清單**  
下列範例顯示如何為成功完成的組織請求帳戶建立請求清單：  

```
aws organizations list-create-account-status --states SUCCEEDED
```
輸出包含物件陣列，其中包含每個請求的相關資訊。  

```
{
        "CreateAccountStatuses": [
                {
                        "AccountId": "444444444444",
                        "AccountName": "Developer Test Account",
                        "CompletedTimeStamp": 1481835812.143,
                        "Id": "car-examplecreateaccountrequestid111",
                        "RequestedTimeStamp": 1481829432.531,
                        "State": "SUCCEEDED"
                }
        ]
}
```
**範例 2：擷取目前組織中提出的進行中帳戶建立請求清單**  
下列範例會取得組織的進行中帳戶建立請求清單：  

```
aws organizations list-create-account-status --states IN_PROGRESS
```
輸出包含物件陣列，其中包含每個請求的相關資訊。  

```
{
        "CreateAccountStatuses": [
                {
                  "State": "IN_PROGRESS",
                  "Id": "car-examplecreateaccountrequestid111",
                  "RequestedTimeStamp": 1481829432.531,
                  "AccountName": "Production Account"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListCreateAccountStatus](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-create-account-status.html)。

### `list-handshakes-for-account`
<a name="organizations_ListHandshakesForAccount_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-handshakes-for-account`。

**AWS CLI**  
**擷取傳送至帳戶的交握清單**  
下列範例示範如何取得與用來呼叫操作之登入資料帳戶相關聯的所有交握清單：  

```
aws organizations list-handshakes-for-account
```
輸出包含交握結構清單，其中包含每個交握的相關資訊，包括其目前狀態：  

```
{
        "Handshake": {
                "Action": "INVITE",
                "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111",
                "ExpirationTimestamp": 1482952459.257,
                "Id": "h-examplehandshakeid111",
                "Parties": [
                        {
                                "Id": "o-exampleorgid",
                                "Type": "ORGANIZATION"
                        },
                        {
                                "Id": "juan@example.com",
                                "Type": "EMAIL"
                        }
                ],
                "RequestedTimestamp": 1481656459.257,
                "Resources": [
                        {
                                "Resources": [
                                        {
                                                "Type": "MASTER_EMAIL",
                                                "Value": "bill@amazon.com"
                                        },
                                        {
                                                "Type": "MASTER_NAME",
                                                "Value": "Org Master Account"
                                        },
                                        {
                                                "Type": "ORGANIZATION_FEATURE_SET",
                                                "Value": "FULL"
                                        }
                                ],
                                "Type": "ORGANIZATION",
                                "Value": "o-exampleorgid"
                        },
                        {
                                "Type": "EMAIL",
                                "Value": "juan@example.com"
                        }
                ],
                "State": "OPEN"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListHandshakesForAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-handshakes-for-account.html)。

### `list-handshakes-for-organization`
<a name="organizations_ListHandshakesForOrganization_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-handshakes-for-organization`。

**AWS CLI**  
**擷取與組織相關聯的交握清單**  
下列範例示範如何取得與目前組織相關聯的交握清單：  

```
aws organizations list-handshakes-for-organization
```
輸出會顯示兩個交握。第一個是 Juan 帳戶的邀請，並顯示 OPEN 狀態。第二個是 Anika 帳戶的邀請，並顯示 ACCEPTED 狀態：  

```
{
        "Handshakes": [
                {
                        "Action": "INVITE",
                        "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111",
                        "ExpirationTimestamp": 1482952459.257,
                        "Id": "h-examplehandshakeid111",
                        "Parties": [
                                {
                                        "Id": "o-exampleorgid",
                                        "Type": "ORGANIZATION"
                                },
                                {
                                        "Id": "juan@example.com",
                                        "Type": "EMAIL"
                                }
                        ],
                        "RequestedTimestamp": 1481656459.257,
                        "Resources": [
                                {
                                        "Resources": [
                                                {
                                                        "Type": "MASTER_EMAIL",
                                                        "Value": "bill@amazon.com"
                                                },
                                                {
                                                        "Type": "MASTER_NAME",
                                                        "Value": "Org Master Account"
                                                },
                                                {
                                                        "Type": "ORGANIZATION_FEATURE_SET",
                                                        "Value": "FULL"
                                                }
                                        ],
                                        "Type": "ORGANIZATION",
                                        "Value": "o-exampleorgid"
                                },
                                {
                                        "Type": "EMAIL",
                                        "Value": "juan@example.com"
                                },
                                {
                                        "Type":"NOTES",
                                        "Value":"This is an invitation to Juan's account to join Bill's organization."
                                }
                        ],
                        "State": "OPEN"
                },
                {
                        "Action": "INVITE",
                        "State":"ACCEPTED",
                        "Arn": "arn:aws:organizations::111111111111:handshake/o-exampleorgid/invite/h-examplehandshakeid111",
                        "ExpirationTimestamp": 1.471797437427E9,
                        "Id": "h-examplehandshakeid222",
                        "Parties": [
                                {
                                        "Id": "o-exampleorgid",
                                        "Type": "ORGANIZATION"
                                },
                                {
                                        "Id": "anika@example.com",
                                        "Type": "EMAIL"
                                }
                        ],
                        "RequestedTimestamp": 1.469205437427E9,
                        "Resources": [
                                {
                                        "Resources": [
                                                {
                                                        "Type":"MASTER_EMAIL",
                                                        "Value":"bill@example.com"
                                                },
                                                {
                                                        "Type":"MASTER_NAME",
                                                        "Value":"Master Account"
                                                }
                                        ],
                                        "Type":"ORGANIZATION",
                                        "Value":"o-exampleorgid"
                                },
                                {
                                        "Type":"EMAIL",
                                        "Value":"anika@example.com"
                                },
                                {
                                        "Type":"NOTES",
                                        "Value":"This is an invitation to Anika's account to join Bill's organization."
                                }
                        ]
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListHandshakesForOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-handshakes-for-organization.html)。

### `list-organizational-units-for-parent`
<a name="organizations_ListOrganizationalUnitsForParent_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-organizational-units-for-parent`。

**AWS CLI**  
**擷取父 OU 或根帳戶中的 OU 清單**  
下列範例示範如何取得指定根帳戶中的 OU 清單：  

```
aws organizations list-organizational-units-for-parent --parent-id r-examplerootid111
```
輸出顯示指定的根帳戶包含兩個 OU 並顯示每個的詳細資訊：  

```
{
        "OrganizationalUnits": [
                {
                        "Name": "AccountingDepartment",
                        "Arn": "arn:aws:organizations::o-exampleorgid:ou/r-examplerootid111/ou-examplerootid111-exampleouid111"
                },
                {
                        "Name": "ProductionDepartment",
                        "Arn": "arn:aws:organizations::o-exampleorgid:ou/r-examplerootid111/ou-examplerootid111-exampleouid222"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListOrganizationalUnitsForParent](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-organizational-units-for-parent.html)。

### `list-parents`
<a name="organizations_ListParents_cli_topic"></a>

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

**AWS CLI**  
**列出帳戶或子 OU 的父 OU 或根帳戶**  
下列範例說明如何列出包含該帳戶 444444444444 的根帳戶或父 OU：  

```
aws organizations list-parents --child-id 444444444444
```
輸出顯示指定的帳戶位於具有指定 ID 的 OU 中：  

```
{
  "Parents": [
        {
          "Id": "ou-examplerootid111-exampleouid111",
          "Type": "ORGANIZATIONAL_UNIT"
        }
  ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListParents](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-parents.html)。

### `list-policies-for-target`
<a name="organizations_ListPoliciesForTarget_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-policies-for-target`。

**AWS CLI**  
**擷取直接連接到帳戶的 SCP 清單**  
下列範例顯示如何取得直接連接至帳戶之篩選條件參數所指定之所有服務控制政策 (SCP) 的清單：  

```
aws organizations list-policies-for-target --filter SERVICE_CONTROL_POLICY --target-id 444444444444
```
輸出包含政策結構的清單，其中包含政策的摘要資訊。此清單不包含套用到帳戶的政策，因為繼承自 OU 階層中的位置：  

```
{
        "Policies": [
                {
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Name": "AllowAllEC2Actions",
                        "AwsManaged", false,
                        "Id": "p-examplepolicyid222",
                        "Arn": "arn:aws:organizations::o-exampleorgid:policy/service_control_policy/p-examplepolicyid222",
                        "Description": "Enables account admins to delegate permissions for any EC2 actions to users and roles in their accounts."
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPoliciesForTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-policies-for-target.html)。

### `list-policies`
<a name="organizations_ListPolicies_cli_topic"></a>

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

**AWS CLI**  
**擷取特定類型組織中所有政策的清單**  
下列範例示範如何取得篩選條件參數所指定的 SCP 清單：  

```
aws organizations list-policies --filter SERVICE_CONTROL_POLICY
```
輸出包含具有摘要資訊的政策清單：  

```
{
        "Policies": [
                {
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Name": "AllowAllS3Actions",
                        "AwsManaged": false,
                        "Id": "p-examplepolicyid111",
                        "Arn": "arn:aws:organizations::111111111111:policy/service_control_policy/p-examplepolicyid111",
                        "Description": "Enables account admins to delegate permissions for any S3 actions to users and roles in their accounts."
                },
                {
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Name": "AllowAllEC2Actions",
                        "AwsManaged": false,
                        "Id": "p-examplepolicyid222",
                        "Arn": "arn:aws:organizations::111111111111:policy/service_control_policy/p-examplepolicyid222",
                        "Description": "Enables account admins to delegate permissions for any EC2 actions to users and roles in their accounts."
                },
                {
                        "AwsManaged": true,
                        "Description": "Allows access to every operation",
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Id": "p-FullAWSAccess",
                        "Arn": "arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccess",
                        "Name": "FullAWSAccess"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPolicies](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-policies.html)。

### `list-roots`
<a name="organizations_ListRoots_cli_topic"></a>

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

**AWS CLI**  
**擷取組織中根帳戶的清單**  
此範例說明如何取得組織的根帳戶清單：  

```
aws organizations list-roots
```
輸出包含具有摘要資訊的根結構清單：  

```
{
        "Roots": [
                {
                        "Name": "Root",
                        "Arn": "arn:aws:organizations::111111111111:root/o-exampleorgid/r-examplerootid111",
                        "Id": "r-examplerootid111",
                        "PolicyTypes": [
                                {
                                        "Status":"ENABLED",
                                        "Type":"SERVICE_CONTROL_POLICY"
                                }
                        ]
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListRoots](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-roots.html)。

### `list-targets-for-policy`
<a name="organizations_ListTargetsForPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-targets-for-policy`。

**AWS CLI**  
**擷取政策連接的所有根帳戶、OU 和帳戶清單**  
下列範例顯示如何取得指定政策所連接根帳戶、OU 和帳戶的清單。  

```
aws organizations list-targets-for-policy --policy-id p-FullAWSAccess
```
輸出包含連接物件的清單，其中包含政策所連接根帳戶、OU 和帳戶的摘要資訊：  

```
{
        "Targets": [
                {
                        "Arn": "arn:aws:organizations::111111111111:root/o-exampleorgid/r-examplerootid111",
                        "Name": "Root",
                        "TargetId":"r-examplerootid111",
                        "Type":"ROOT"
                },
                {
                        "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/333333333333;",
                        "Name": "Developer Test Account",
                        "TargetId": "333333333333",
                        "Type": "ACCOUNT"
                },
                {
                        "Arn":"arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111",
                        "Name":"Accounting",
                        "TargetId":"ou-examplerootid111-exampleouid111",
                        "Type":"ORGANIZATIONAL_UNIT"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTargetsForPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-targets-for-policy.html)。

### `move-account`
<a name="organizations_MoveAccount_cli_topic"></a>

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

**AWS CLI**  
**在根帳戶或 OU 之間移動帳戶**  
下列範例示範如何將組織中的主帳戶從根帳戶移至 OU：  

```
aws organizations move-account --account-id 333333333333 --source-parent-id r-examplerootid111 --destination-parent-id ou-examplerootid111-exampleouid111
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [MoveAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/move-account.html)。

### `remove-account-from-organization`
<a name="organizations_RemoveAccountFromOrganization_cli_topic"></a>

以下程式碼範例顯示如何使用 `remove-account-from-organization`。

**AWS CLI**  
**將帳戶從組織中移除為主帳戶**  
下列範例示範如何從組織移除帳戶：  

```
aws organizations remove-account-from-organization --account-id 333333333333
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [RemoveAccountFromOrganization](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/remove-account-from-organization.html)。

### `update-organizational-unit`
<a name="organizations_UpdateOrganizationalUnit_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-organizational-unit`。

**AWS CLI**  
**重新命名 OU**  
此範例說明如何重新命名 OU：在此範例中，OU 已重新命名為 "AccountingOU"：  

```
aws organizations update-organizational-unit --organizational-unit-id ou-examplerootid111-exampleouid111 --name AccountingOU
```
輸出會顯示新名稱：  

```
{
        "OrganizationalUnit": {
                "Id": "ou-examplerootid111-exampleouid111"
                "Name": "AccountingOU",
                "Arn": "arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111""
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateOrganizationalUnit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/update-organizational-unit.html)。

### `update-policy`
<a name="organizations_UpdatePolicy_cli_topic"></a>

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

**AWS CLI**  
**範例 1：重新命名政策**  
下列 `update-policy` 範例會重新命名政策，並提供新的描述。  

```
aws organizations update-policy \
    --policy-id p-examplepolicyid111 \
    --name Renamed-Policy \
    --description "This description replaces the original."
```
輸出會顯示新名稱和描述。  

```
{
    "Policy": {
        "Content": "{\n  \"Version\":\"2012-10-17\",\n  \"Statement\":{\n    \"Effect\":\"Allow\",\n    \"Action\":\"ec2:*\",\n    \"Resource\":\"*\"\n  }\n}\n",
        "PolicySummary": {
            "Id": "p-examplepolicyid111",
            "AwsManaged": false,
            "Arn":"arn:aws:organizations::111111111111:policy/o-exampleorgid/service_control_policy/p-examplepolicyid111",
            "Description": "This description replaces the original.",
            "Name": "Renamed-Policy",
            "Type": "SERVICE_CONTROL_POLICY"
        }
    }
}
```
**範例 2：取代政策的 JSON 文字內容**  
下列範例示範如何使用允許 S3 而非 EC2 的新 JSON 政策文字字串取代先前範例中 SCP 的 JSON 文字：  

```
aws organizations update-policy \
    --policy-id p-examplepolicyid111 \
    --content "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"s3:*\",\"Resource\":\"*\"}}"
```
輸出會顯示新內容：  

```
{
    "Policy": {
        "Content": "{ \"Version\": \"2012-10-17\", \"Statement\": { \"Effect\": \"Allow\", \"Action\": \"s3:*\", \"Resource\": \"*\" } }",
        "PolicySummary": {
            "Arn": "arn:aws:organizations::111111111111:policy/o-exampleorgid/service_control_policy/p-examplepolicyid111",
            "AwsManaged": false;
            "Description": "This description replaces the original.",
            "Id": "p-examplepolicyid111",
            "Name": "Renamed-Policy",
            "Type": "SERVICE_CONTROL_POLICY"
        }
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdatePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/update-policy.html)。