

第 5 版 (V5) AWS Tools for PowerShell 已發行！

如需有關中斷變更和遷移應用程式的資訊，請參閱[遷移主題](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

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

# 在 中呼叫 AWS 服務 AWS Tools for PowerShell
<a name="pstools-using"></a>

本節提供使用 AWS Tools for PowerShell 存取 AWS 服務的範例。這些範例有助於示範如何使用 cmdlet 來執行實際 AWS 任務。這些範例會依賴 Tools for PowerShell 所提供的 cmdlet。若要查看有哪些 cmdlet 可用，請參閱 [AWS Tools for PowerShell cmdlet 參考](https://docs.aws.amazon.com/powershell/v5/reference/)。

您可以在 [程式碼範例](powershell_code_examples.md)章節中找到更多 AWS Tools for PowerShell 範例。

## PowerShell 檔案串連編碼
<a name="powershell-file-concatenation-encoding"></a>

編輯現有 AWS Tools for PowerShell 檔案或記錄中的某些 cmdlet AWS。範例為 `Edit-R53ResourceRecordSet`，這會呼叫適用於 Amazon Route 53 的 [ChangeResourceRecordSets](https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html) API。

當您在 PowerShell 5.1 或較舊版本中編輯或串連檔案時，PowerShell 會以 UTF-16 而非 UTF-8 輸出編碼。這可能增加不必要的字元，並產生無效的結果。十六進位編輯器可能展現不必要的字元。

為了避免將檔案輸出轉換為 UTF-16，您可以將命令輸送到 PowerShell 的 `Out-File` cmdlet 並指定 UTF-8 編碼，如以下範例所示。

```
PS > *some file concatenation command* | Out-File filename.txt -Encoding utf8
```

如果您是從 PowerShell 主控台執行 AWS CLI 命令，則適用相同的行為。您可以在 `Out-File` PowerShell 主控台中將 AWS CLI 命令的輸出輸送至 。其他 cmdlet，例如 `Export-Csv` 或 `Export-Clixml`，也有一個 `Encoding` 參數。如需具有 `Encoding` 參數以及可讓您更正串連檔案輸出編碼的 cmdlet 完整清單，請執行下列命令：

```
PS > Get-Command -ParameterName "Encoding"
```

**注意**  
PowerShell 6.0 和更新版本 (包括 PowerShell Core) 會自動保留 UTF-8 編碼以供串連檔案輸出。

## Powershell 工具傳回的物件
<a name="returned-objects-for-the-powershell-tools"></a>

為了在原生 PowerShell 環境中 AWS Tools for PowerShell 更實用， AWS Tools for PowerShell Cmdlet 傳回的物件是 .NET 物件，而不是通常從 AWS SDK 中對應 API 傳回的 JSON 文字物件。例如，`Get-S3Bucket` 會發出 `Buckets` 集合，而非 Amazon S3 JSON 回應物件。`Buckets` 集合可以放置在 PowerShell 管道中，並以適當的方式與之互動。同樣地，`Get-EC2Instance` 會發出 `Reservation` .NET 物件 集合，而非 `DescribeEC2Instances` JSON 結果物件。此行為是設計而成，可讓 AWS Tools for PowerShell 體驗與慣用的 PowerShell 更一致。

如有需要，您可取得實際的服務回應。它們會儲存為傳回物件上的 `note` 屬性。而透過使用 `NextToken` 欄位支援分頁的 API 動作，也會連接為 `note` 屬性。

## [Amazon EC2](pstools-ec2.md)
<a name="using-ec2"></a>

本節會逐步講解啟動 Amazon EC2 執行個體所需的步驟，其包括以下作業：
+ 擷取 Amazon Machine Image (AMI) 的清單。
+ 建立 SSH 驗證的金鑰對。
+ 建立並設定 Amazon EC2 安全群組。
+ 啟動執行個體，並擷取該執行個體的相關資訊。

## [Amazon S3](pstools-s3.md)
<a name="using-s3"></a>

本節會逐步講解建立靜態網站並託管於 Amazon S3 所需的步驟，其將示範以下作業：
+ 建立與刪除 Amazon S3 儲存貯體。
+ 將檔案以物件形式上傳至 Amazon S3 儲存貯體。
+ 刪除 Amazon S3 儲存貯體中的物件。
+ 將 Amazon S3 儲存貯體指定為網站。

## [AWS Lambda 而且 AWS Tools for PowerShell](pstools-lambda.md)
<a name="using-lambda"></a>

本節提供 AWS Lambda Tools for PowerShell 模組的簡短概觀，並說明設定模組所需的步驟。

## [Amazon SNS 和 Amazon SQS](pstools-sqs-queue-sns-topic.md)
<a name="using-sns"></a>

本節會逐步講解將 Amazon SQS 佇列訂閱至 Amazon SNS 主題所需的步驟。其將示範以下作業：
+ 建立 Amazon SNS 主題。
+ 建立 Amazon SQS 佇列。
+ 將佇列訂閱至 主題。
+ 傳送訊息至主題。
+ 從佇列接收訊息。

## [CloudWatch](pstools-cw.md)
<a name="using-cw"></a>

您可以善用本節提供的範例，藉此了解如何將自訂資料發布至 CloudWatch。
+ 發布自訂指標至 CloudWatch 儀表板。

## 另請參閱
<a name="see-also"></a>
+  [設定和使用 AWS Tools for PowerShell](pstools-getting-started.md) 

## 主題
<a name="w2aac13c23"></a>
+ [Amazon S3 和 Tools for Windows PowerShell](pstools-s3.md)
+ [Amazon EC2 與 Tools for Windows PowerShell](pstools-ec2.md)
+ [AWS Lambda 而且 AWS Tools for PowerShell](pstools-lambda.md)
+ [Amazon SQS、Amazon SNS 和 Tools for Windows PowerShell](pstools-sqs-queue-sns-topic.md)
+ [來自 的 CloudWatch AWS Tools for Windows PowerShell](pstools-cw.md)
+ [在 cmdlets 中使用用 ClientConfig 參數](pstools-clientconfig.md)