

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

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

# 搭配使用 `GetTrailStatus` 與 CLI
<a name="cloudtrail_example_cloudtrail_GetTrailStatus_section"></a>

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

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

**AWS CLI**  
**取得追蹤的狀態**  
下列 `get-trail-status` 命令傳回 `Trail1` 的交付和記錄詳細資訊：  

```
aws cloudtrail get-trail-status --name Trail1
```
輸出：  

```
{
  "LatestNotificationTime": 1454022144.869,
  "LatestNotificationAttemptSucceeded": "2016-01-28T23:02:24Z",
  "LatestDeliveryAttemptTime": "2016-01-28T23:02:24Z",
  "LatestDeliveryTime": 1454022144.869,
  "TimeLoggingStarted": "2015-11-06T18:36:38Z",
  "LatestDeliveryAttemptSucceeded": "2016-01-28T23:02:24Z",
  "IsLogging": true,
  "LatestCloudWatchLogsDeliveryTime": 1454022144.918,
  "StartLoggingTime": 1446834998.695,
  "StopLoggingTime": 1446834996.933,
  "LatestNotificationAttemptTime": "2016-01-28T23:02:24Z",
  "TimeLoggingStopped": "2015-11-06T18:36:36Z"
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetTrailStatus](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudtrail/get-trail-status.html)。

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

**Tools for PowerShell V4**  
**範例 1：傳回名為 'myExampleTrail' 的追蹤狀態資訊。傳回的資料包含交付錯誤、Amazon SNS 和 Amazon S3 錯誤，以及開始和停止追蹤記錄時間的相關資訊。此範例假設追蹤是在與目前 shell 預設值相同的區域中建立的。**  

```
Get-CTTrailStatus -Name myExampleTrail
```
**範例 2：傳回在目前 shell 預設值 (在本案例中為法蘭克福 (eu-central-1) 區域) 以外區域中建立的追蹤狀態資訊。**  

```
Get-CTTrailStatus -Name myExampleTrail -Region eu-central-1
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [GetTrailStatus](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：傳回名為 'myExampleTrail' 的追蹤狀態資訊。傳回的資料包含交付錯誤、Amazon SNS 和 Amazon S3 錯誤，以及開始和停止追蹤記錄時間的相關資訊。此範例假設追蹤是在與目前 shell 預設值相同的區域中建立的。**  

```
Get-CTTrailStatus -Name myExampleTrail
```
**範例 2：傳回在目前 shell 預設值 (在本案例中為法蘭克福 (eu-central-1) 區域) 以外區域中建立的追蹤狀態資訊。**  

```
Get-CTTrailStatus -Name myExampleTrail -Region eu-central-1
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetTrailStatus](https://docs.aws.amazon.com/powershell/v5/reference)。

------