

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

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

# 搭配使用 `ListHostedZonesByName` 與 CLI
<a name="route-53_example_route-53_ListHostedZonesByName_section"></a>

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

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

**AWS CLI**  
下列命令會列出最多 100 個依網域名稱排序的託管區域：  

```
aws route53 list-hosted-zones-by-name
```
輸出：  

```
{
  "HostedZones": [
      {
          "ResourceRecordSetCount": 2,
          "CallerReference": "test20150527-2",
          "Config": {
              "Comment": "test2",
              "PrivateZone": false
          },
          "Id": "/hostedzone/Z119WBBTVP5WFX",
          "Name": "2.example.com."
      },
      {
          "ResourceRecordSetCount": 2,
          "CallerReference": "test20150527-1",
          "Config": {
              "Comment": "test",
              "PrivateZone": false
          },
          "Id": "/hostedzone/Z3P5QSUBK4POTI",
          "Name": "www.example.com."
      }
  ],
  "IsTruncated": false,
  "MaxItems": "100"
}
```
下列命令會列出依名稱排序的託管區域，開頭為 `www.example.com`：  

```
aws route53 list-hosted-zones-by-name --dns-name www.example.com
```
輸出：  

```
{
  "HostedZones": [
      {
          "ResourceRecordSetCount": 2,
          "CallerReference": "mwunderl20150527-1",
          "Config": {
              "Comment": "test",
              "PrivateZone": false
          },
          "Id": "/hostedzone/Z3P5QSUBK4POTI",
          "Name": "www.example.com."
      }
  ],
  "DNSName": "www.example.com",
  "IsTruncated": false,
  "MaxItems": "100"
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListHostedZonesByName](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53/list-hosted-zones-by-name.html)。

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

**Tools for PowerShell V4**  
**範例 1：依網域名稱，以 ASCII 順序傳回所有公有和私有託管區域。**  

```
Get-R53HostedZonesByName
```
**範例 2：依網域名稱，以 ASCII 順序傳回公有和私有託管區域，從指定的 DNS 名稱開始。**  

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

**Tools for PowerShell V5**  
**範例 1：依網域名稱，以 ASCII 順序傳回所有公有和私有託管區域。**  

```
Get-R53HostedZonesByName
```
**範例 2：依網域名稱，以 ASCII 順序傳回公有和私有託管區域，從指定的 DNS 名稱開始。**  

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

------