

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

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

# 搭配使用 `ListStacks` 與 CLI
<a name="cloudformation_example_cloudformation_ListStacks_section"></a>

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

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

**AWS CLI**  
**列出 AWS CloudFormation 堆疊**  
以下 `list-stacks` 命令示範狀態為 `CREATE_COMPLETE` 之所有堆疊的摘要：  

```
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE
```
輸出：  

```
[
    {
        "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896",
        "TemplateDescription": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
        "StackStatusReason": null,
        "CreationTime": "2013-08-26T03:27:10.190Z",
        "StackName": "myteststack",
        "StackStatus": "CREATE_COMPLETE"
    }
]
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListStacks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stacks.html)。

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

**Tools for PowerShell V4**  
**範例 1：傳回所有堆疊的摘要資訊。**  

```
Get-CFNStackSummary
```
**範例 2：傳回目前正在建立之所有堆疊的摘要資訊。**  

```
Get-CFNStackSummary -StackStatusFilter "CREATE_IN_PROGRESS"
```
**範例 3：傳回目前正在建立或更新之所有堆疊的摘要資訊。**  

```
Get-CFNStackSummary -StackStatusFilter @("CREATE_IN_PROGRESS", "UPDATE_IN_PROGRESS")
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [ListStacks](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：傳回所有堆疊的摘要資訊。**  

```
Get-CFNStackSummary
```
**範例 2：傳回目前正在建立之所有堆疊的摘要資訊。**  

```
Get-CFNStackSummary -StackStatusFilter "CREATE_IN_PROGRESS"
```
**範例 3：傳回目前正在建立或更新之所有堆疊的摘要資訊。**  

```
Get-CFNStackSummary -StackStatusFilter @("CREATE_IN_PROGRESS", "UPDATE_IN_PROGRESS")
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListStacks](https://docs.aws.amazon.com/powershell/v5/reference)。

------