

AWS Tools for PowerShell V4 已進入維護模式。

我們建議您遷移至 [AWS Tools for PowerShell V5](https://docs.aws.amazon.com/powershell/v5/userguide/)。如需如何遷移的其他詳細資訊和資訊，請參閱我們的[維護模式公告](https://aws.amazon.com/blogs/developer/aws-tools-for-powershell-v4-maintenance-mode-announcement/)。

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

# 安裝 AWS Tools for PowerShell
<a name="pstools-getting-set-up"></a>

若要成功安裝和使用 AWS Tools for PowerShell cmdlet，請參閱下列主題中的步驟。

**Topics**
+ [在 Windows 上安裝](pstools-getting-set-up-windows.md)
+ [在 Linux 或 macOS 上安裝](pstools-getting-set-up-linux-mac.md)
+ [從 3.3 AWS Tools for PowerShell 版遷移至 第 4 版](v4migration.md)

# 在 Windows AWS Tools for PowerShell 上安裝
<a name="pstools-getting-set-up-windows"></a>

Windows 型電腦可以執行任何 AWS Tools for PowerShell 套件選項：
+ [**`AWS.Tools`**](#ps-installing-awstools) - 的模組化版本 AWS Tools for PowerShell。每個 AWS 服務都由其個別的小型模組支援，具有共用支援模組 `AWS.Tools.Common`和 `AWS.Tools.Installer`。
+ [**AWSPowerShell.NetCore**](#ps-installing-awspowershellnetcore) - 的單一大型模組版本 AWS Tools for PowerShell。此單一大型模組支援所有 AWS 服務。
**注意**  
請注意，單一模組可能太大，無法與 [AWS Lambda](https://aws.amazon.com/lambda/) 功能一起使用。請改用上面的模組化版本。
+ [**AWSPowerShell**](#ps-installing-awswindowspowershell) – AWS Tools for PowerShell的舊式 Windows 專用單一大型模組版本。此單一大型模組支援所有 AWS 服務。

您選擇的套件取決於您正在執行的 Windows 版本。

**注意**  
預設 AWS Tools for PowerShell 會在所有 Windows 型 Amazon Machine Image (AMIs) 上安裝 。已安裝的選項取決於 AMI。許多 AMIs 都有 AWSPowerShell 模組，但有些模組可能有不同的選項。例如，適用於 Windows Server 2025 的 Amazon EC2 AMIs 使用模組化`AWS.Tools`選項。

設定 AWS Tools for PowerShell 涉及下列高階任務，在本主題中詳細說明。

1. 安裝適合您環境的 AWS Tools for PowerShell 套件選項。

1. 執行 `Get-ExecutionPolicy` Cmdlet 來驗證指令碼執行已啟用。

1. 將 AWS Tools for PowerShell 模組匯入 PowerShell 工作階段。

## 先決條件
<a name="prerequisites"></a>

若要從 Microsoft 取得更新版本的 PowerShell (包括 PowerShell Core)，請前往 Microsoft 網站的[安裝各種版本的 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell) 進行下載。

## 在 Windows 上安裝 `AWS.Tools`
<a name="ps-installing-awstools"></a>

您可以在執行 Windows 搭配 Windows PowerShell 5 AWS Tools for PowerShell .1 或 PowerShell Core 6.0 或更新版本的電腦上安裝模組化版本的 。如需如何安裝 PowerShell Core 的相關資訊，請參閱 Microsoft 網站上的[安裝各種版本的 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell) 一文。

有三種方式可以安裝 `AWS.Tools`：
+ 使用 `AWS.Tools.Installer` 模組中的 Cmdlet。此模組可簡化其他`AWS.Tools`模組的安裝和更新。 `AWS.Tools.Installer`需要 `PowerShellGet`，並會自動下載和安裝其更新版本。 `AWS.Tools.Installer`會自動讓您的模組版本保持同步。當您安裝或更新至某個模組的較新版本時， 中的 cmdlet `AWS.Tools.Installer`會自動將所有其他`AWS.Tools`模組更新為相同的版本。

  此方法會在以下程序中說明。
+ 從 `[AWS.Tools.zip](https://sdk-for-net.amazonwebservices.com/ps/v4/latest/AWS.Tools.zip)` 下載模組，然後解壓縮至其中一個模組資料夾。您可以顯示 `PSModulePath` 環境變數的值來探索自己的模組資料夾。
**警告**  
下載 ZIP 檔案之後，在擷取內容之前，您可能需要將其解鎖。這通常透過開啟 檔案的屬性、檢視**一般**索引標籤，以及在存在時選取**解除封鎖**核取方塊來完成。  
如果需要解除封鎖 ZIP 檔案，但您未這麼做，您可能會收到類似下列的錯誤：「匯入模組：無法載入檔案或組件」。
+ 使用 `Install-Module` cmdlet 從 PowerShell Gallery 安裝每個服務模組。

**使用 `AWS.Tools.Installer`模組在 Windows `AWS.Tools`上安裝**

1. 啟動 PowerShell 工作階段。
**注意**  
除非手邊任務需要，否則建議「請勿」**以提高權限的管理員身分執行 PowerShell。這是因為可能會有潛在的安全風險，且不符合最低權限原則。

1. 若要安裝模組化 `AWS.Tools` 套件，請執行以下命令。

   ```
   PS > Install-Module -Name AWS.Tools.Installer
   
   Untrusted repository
   You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure
    you want to install the modules from 'PSGallery'?
   [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
   ```

   若您收到通知，顯示儲存庫「不受信任」，表示系統正在詢問您是否無論如何都要進行安裝。輸入 **y** 來允許 PowerShell 安裝模組。若要在不信任儲存庫的情況下避免出現提示及安裝模組，您可以執行命令搭配 `-Force` 參數。

   ```
   PS > Install-Module -Name AWS.Tools.Installer -Force
   ```

1. 您現在可以使用 `Install-AWSToolsModule` cmdlet 為要使用的每個 AWS 服務安裝 模組。例如，以下命令會安裝 Amazon EC2 和 Amazon S3 模組。此命令也會安裝指定模組運作所需的任何相依模組。例如，當您安裝第一個 `AWS.Tools` 服務模組時，它也會安裝 `AWS.Tools.Common`。這是所有 AWS 服務模組所需的共用模組。它也會移除舊版模組，並將其他模組更新至相同的更新版本。

   ```
   PS > Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp
     Confirm
     Are you sure you want to perform this action?
     Performing the operation "Install-AWSToolsModule" on target "AWS Tools version 4.0.0.0".
     [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
   
     Installing module AWS.Tools.Common version 4.0.0.0
     Installing module AWS.Tools.EC2 version 4.0.0.0
     Installing module AWS.Tools.Glacier version 4.0.0.0
     Installing module AWS.Tools.S3 version 4.0.0.0
   
     Uninstalling AWS.Tools version 3.3.618.0
     Uninstalling module AWS.Tools.Glacier
     Uninstalling module AWS.Tools.S3
     Uninstalling module AWS.Tools.SimpleNotificationService
     Uninstalling module AWS.Tools.SQS
     Uninstalling module AWS.Tools.Common
   ```
**注意**  
`Install-AWSToolsModule` Cmdlet 會從名為 `PSGallery` 的 `PSRepository` ([https://www.powershellgallery.com/](https://www.powershellgallery.com/)) 下載所有要求的模組，並視為是信任的來源。如需此 `PSRepository` 的詳細資訊，請使用 `Get-PSRepository -Name PSGallery` 命令。

   根據預設，前一個命令會將模組安裝至 `%USERPROFILE%\Documents\WindowsPowerShell\Modules` 資料夾中。若要為某部電腦的所有使用者安裝 AWS Tools for PowerShell ，您必須在您以管理員身分啟動的 PowerShell 工作階段中執行以下命令。例如，以下命令會將 IAM 模組安裝至所有使用者可存取的 `%ProgramFiles%\WindowsPowerShell\Modules` 資料夾。

   ```
   PS > Install-AWSToolsModule AWS.Tools.IdentityManagement -Scope AllUsers
   ```

   若要安裝其他模組，請使用適當的模組名稱執行類似的命令，例如 [PowerShell Gallery](https://www.powershellgallery.com/packages?q=aws) 中的命令。

## 在 Windows 上安裝 AWSPowerShell.NetCore
<a name="ps-installing-awspowershellnetcore"></a>

您可以在執行 Windows，且包含 PowerShell 第 3 版到 5.1 版，或是 PowerShell Core 6.0 或更新版本的電腦上安裝 AWSPowerShell.NetCore。如需如何安裝 PowerShell Core 的相關資訊，請參閱 Microsoft PwerShell 網站中的《[安裝各種版本的 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell)》一文。

您可以透過下列兩種方法安裝 AWSPowerShell.NetCore
+ 從 [AWSPowerShell.NetCore.zip](https://sdk-for-net.amazonwebservices.com/ps/v4/latest/AWSPowerShell.NetCore.zip) 下載模組，然後解壓縮至其中一個模組目錄。您可以顯示 `PSModulePath` 環境變數的值來探索自己的模組目錄。
**警告**  
下載 ZIP 檔案之後，在擷取內容之前，您可能需要將其解鎖。這通常是透過開啟 檔案的屬性、檢視**一般**索引標籤，以及在存在時選取**解除封鎖**核取方塊來完成。  
如果需要解除封鎖 ZIP 檔案，但您未這麼做，您可能會收到類似下列的錯誤：「匯入模組：無法載入檔案或組件」。
+ 使用 `Install-Module` Cmdlet 從 PowerShell Gallery 安裝，如下列程序中所描述。

**使用 Install-Module cmdlet 從 PowerShell Gallery 安裝 AWSPowerShell.NetCore**

若要從 PowerShell Gallery 安裝 AWSPowerShell.NetCore，您的電腦必須執行 PowerShell 5.0 或更新版本，或是在 PowerShell 3 或更新版本中執行 [PowerShellGet](https://www.powershellgallery.com/packages/PowerShellGet)。執行下列命令。

```
PS > Install-Module -name AWSPowerShell.NetCore
```

如果您以管理員身分執行 PowerShell，先前的命令會 AWS Tools for PowerShell 為電腦上的所有使用者安裝 。如果您以沒有管理員許可的標準使用者身分執行 PowerShell，則只會 AWS Tools for PowerShell 為目前的使用者安裝相同的命令。

若在使用者具備管理員許可時，僅要為目前的使用者進行安裝，請搭配 `-Scope CurrentUser` 參數執行命令，如下。

```
PS > Install-Module -name AWSPowerShell.NetCore -Scope CurrentUser
```

雖然 PowerShell 3.0 和更新版本通常會在您第一次執行模組中的 Cmdlet 時，將模組載入您的 PowerShell 工作階段，由於 AWSPowerShell.NetCore 模組的大小太大，因此不支援此功能。您必須改為執行以下命令，明確將 AWSPowerShell.NetCore Core 模組載入您的 PowerShell 工作階段。

```
PS > Import-Module AWSPowerShell.NetCore
```

若要自動將 AWSPowerShell.NetCore 模組載入 PowerShell 工作階段，請將該命令新增到您的 PowerShell 描述檔。如需編輯您 PowerShell 描述檔的詳細資訊，請參閱 PowerShell 文件中的 [About Profiles](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_profiles)。

## 在 Windows PowerShell 上安裝 AWSPowerShell
<a name="ps-installing-awswindowspowershell"></a>

您可以透過下列兩種方式 AWS Tools for Windows PowerShell 之一安裝 ：
+ 從 [AWSPowerShell.zip](https://sdk-for-net.amazonwebservices.com/ps/v4/latest/AWSPowerShell.zip) 下載模組，然後解壓縮至其中一個模組目錄。您可以顯示 `PSModulePath` 環境變數的值來探索自己的模組目錄。
**警告**  
下載 ZIP 檔案之後，在擷取內容之前，您可能需要將其解鎖。這通常是透過開啟 檔案的屬性、檢視**一般**索引標籤，以及在存在時選取**解除封鎖**核取方塊來完成。  
如果需要解除封鎖 ZIP 檔案，但您未這麼做，您可能會收到類似下列的錯誤：「匯入模組：無法載入檔案或組件」。
+ 使用 `Install-Module` Cmdlet 從 PowerShell Gallery 安裝，如下列程序中所描述。

**使用 Install-Module cmdlet 從 PowerShell Gallery 安裝 AWSPowerShell**

如果您正在執行 PowerShell 5.0 或更新版本，或是已在 PowerShell 3 或更新版本上安裝 [PowerShellGet](https://www.powershellgallery.com/packages/PowerShellGet)，可以從 PowerShell Gallery 安裝 AWSPowerShell。您可以執行以下命令，從 Microsoft 的 [PowerShell Gallery](https://www.powershellgallery.com/packages/AWSPowerShell) 安裝並更新 SWSPowerShell。

```
 PS > Install-Module -Name AWSPowerShell
```

若要將 AWSPowerShell 模組自動載入 PowerShell 工作階段，請將先前的 `import-module` Cmdlet 新增到您的 PowerShell 描述檔。如需編輯您 PowerShell 描述檔的詳細資訊，請參閱 PowerShell 文件中的 [About Profiles](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-6)。

**注意**  
Tools for Windows PowerShell 根據預設會安裝在所有 Windows 類型的 Amazon Machine Image (AMI) 上。

## 啟用指令碼執行
<a name="enable-script-execution"></a>

若要載入 AWS Tools for PowerShell 模組，您必須啟用 PowerShell 指令碼執行。欲啟用指令碼執行，請執行 `Set-ExecutionPolicy` cmdlet 來設定 `RemoteSigned` 政策。如需詳細資訊，請參閱 Microsoft Technet 網站上的 [About Execution Policies](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies)。

**注意**  
此需求僅適用於執行 Windows 的電腦。`ExecutionPolicy` 安全限制不會出現在其他作業系統上。

 **啟用指令碼執行** 

1. 需要管理員權限才能設定執行政策。若您並非以具備管理員權限的使用者登入，請以管理員身分開啟 PowerShell 工作階段。選擇 **Start (開始)**，然後選擇 **All Programs (所有程式)**。選擇 **Accessories (附屬應用程式)**，然後選擇 **Windows PowerShell**。以滑鼠右鍵按一下 **Windows PowerShell**，然後在內容選單上，選擇 **Run as administrator (以系統管理員身分執行)**。

1. 在命令提示中，輸入以下內容。

   ```
   PS > Set-ExecutionPolicy RemoteSigned 
   ```

**注意**  
在 64 位元系統上，您必須為 32 位元版本的 PowerShell (**Windows PowerShell (x86)**) 個別執行此作業。

若您沒有正確設定執行政策，PowerShell 會在您嘗試執行指令碼 (例如您的描述檔) 時顯示以下錯誤。

```
File C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because the execution
 of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:2
+ . <<<<  'C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException
```

Tools for Windows PowerShell 安裝程式會自動更新 [PSModulePath](http://msdn.microsoft.com/en-us/library/windows/desktop/dd878326.aspx)，納入內含 `AWSPowerShell` 模組的目錄位置。

由於 `PSModulePath`包含 AWS 模組目錄的位置，因此 `Get-Module -ListAvailable` cmdlet 會顯示模組。

```
PS > Get-Module -ListAvailable

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   AppLocker                 {}
Manifest   BitsTransfer              {}
Manifest   PSDiagnostics             {}
Manifest   TroubleshootingPack       {}
Manifest   AWSPowerShell             {Update-EBApplicationVersion, Set-DPStatus, Remove-IAMGroupPol...
```

## 版本控制
<a name="pstools-versioning"></a>

AWS AWS Tools for PowerShell 會定期發行 的新版本，以支援新的 AWS 服務和功能。若要確認您已安裝的工具版本，請執行 [Get-AWSPowerShellVersion](https://docs.aws.amazon.com/powershell/v4/reference/items/Get-AWSPowerShellVersion.html) Cmdlet。

例如：

```
PS > Get-AWSPowerShellVersion

AWS Tools for PowerShell
Version 4.1.849
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Amazon Web Services SDK for .NET
Core Runtime Version 3.7.402.75
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Release notes: https://github.com/aws/aws-tools-for-powershell/blob/v4.1/changelogs/CHANGELOG.ALL.md

This software includes third party software subject to the following copyrights:
- Logging from log4net, Apache License
[http://logging.apache.org/log4net/license.html]
```

您也可以將 `-ListServiceVersionInfo` 參數新增至 [Get-AWSPowerShellVersion](https://docs.aws.amazon.com/powershell/v4/reference/items/Get-AWSPowerShellVersion.html) 命令，以查看目前版本工具中支援的 AWS 服務清單。若您使用模組化的 `AWS.Tools.*` 選項，則只會顯示您目前已匯入的模組。

例如：

```
PS > Get-AWSPowerShellVersion -ListServiceVersionInfo
...

Service                            Noun Prefix Module Name                       SDK
                                                                                 Assembly
                                                                                 Version
-------                            ----------- -----------                       -----------
AWS IAM Access Analyzer            IAMAA       AWS.Tools.AccessAnalyzer          3.7.400.33
AWS Account                        ACCT        AWS.Tools.Account                 3.7.400.33
AWS Certificate Manager Private... PCA         AWS.Tools.ACMPCA                  3.7.400.34
AWS Amplify                        AMP         AWS.Tools.Amplify                 3.7.401.28
Amplify Backend                    AMPB        AWS.Tools.AmplifyBackend          3.7.400.33
...
```

若要確認您執行的 PowerShell 版本，請輸入 `$PSVersionTable` 來檢視 \$1PSVersionTable [自動變數](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6)的內容。

例如：

```
PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
```

## 在 Windows AWS Tools for PowerShell 上更新
<a name="pstools-updating"></a>

定期 AWS Tools for PowerShell 發行更新版本的 時，您應該更新在本機執行的版本。

### 更新模組化`AWS.Tools`模組
<a name="update-the-tools-for-powershell"></a>

若要將`AWS.Tools`模組更新至最新版本，請執行下列命令：

```
PS > Update-AWSToolsModule -CleanUp
```

此命令會更新所有目前安裝的 `AWS.Tools` 模組，並且會在更新成功後移除其他安裝的版本。

**注意**  
`Update-AWSToolsModule` Cmdlet 會從名為 `PSGallery` 的 `PSRepository` ([https://www.powershellgallery.com/](https://www.powershellgallery.com/)) 下載所有模組，並視為是信任的來源。如需此 `PSRepository` 的詳細資訊，請使用 `Get-PSRepository -Name PSGallery` 命令。

### 更新 Tools for PowerShell Core
<a name="update-the-tools-for-powershell-core"></a>

執行 `Get-AWSPowerShellVersion` Cmdlet 來確認您正在執行的版本，並將此版本與 [PowerShell Gallery](https://www.powershellgallery.com/packages/AWSPowerShell) 網站上可用的 Tools for Windows PowerShell 版本進行比較。我們建議您每兩到三週檢查一次。只有在您更新到具有該支援的版本之後，才能支援新的命令 AWS 和服務。

安裝 AWSPowerShell.NetCore 的較新版本前，請解除安裝現有模組。請在您解除安裝現有套件前關閉任何開啟的 PowerShell 工作階段。執行下列命令以解除安裝套件。

```
PS > Uninstall-Module -Name AWSPowerShell.NetCore -AllVersions
```

解除安裝套件後，請執行以下命令來安裝更新後的模組。

```
PS > Install-Module -Name AWSPowerShell.NetCore
```

安裝完成後，請執行 `Import-Module AWSPowerShell.NetCore` 命令來將更新後的 Cmdlet 載入您的 PowerShell 工作階段。

### 更新 Tools for Windows PowerShell
<a name="update-the-tools-for-windows-powershell"></a>

執行 `Get-AWSPowerShellVersion` Cmdlet 來確認您正在執行的版本，並將此版本與 [PowerShell Gallery](https://www.powershellgallery.com/packages/AWSPowerShell) 網站上可用的 Tools for Windows PowerShell 版本進行比較。我們建議您每兩到三週檢查一次。只有在您更新到具有該支援的版本之後，才能支援新的命令 AWS 和服務。
+ 若您使用 `Install-Module` Cmdlet 進行安裝，請執行下列命令。

  ```
  PS > Uninstall-Module -Name AWSPowerShell -AllVersions
  PS > Install-Module -Name AWSPowerShell
  ```
+ 若您使用下載的 ZIP 檔案安裝：

  1. 從 [Tools for PowerShell](https://aws.amazon.com/powershell/) 網站下載最新版本。將所下載檔案名稱中的套件版本號碼，與您在執行 `Get-AWSPowerShellVersion` Cmdlet 時取得的版本號碼進行比較。

  1. 若下載版本的數字比您安裝的版本更高，請關閉所有 Tools for Windows PowerShell 主控台。

  1. 安裝較新版本 Tools for Windows PowerShell。

安裝完成後，請執行 `Import-Module AWSPowerShell` 來將更新後的 Cmdlet 載入您的 PowerShell 工作階段。或者，從**開始**功能表執行自訂 AWS Tools for PowerShell 主控台。

# 在 Linux 或 macOS AWS Tools for PowerShell 上安裝
<a name="pstools-getting-set-up-linux-mac"></a>

本主題說明如何在 Linux 或 macOS AWS Tools for PowerShell 上安裝 。

## 設定概觀
<a name="pstools-installing-core-prerequisites"></a>

若要 AWS Tools for PowerShell 在 Linux 或 macOS 電腦上安裝 ，您可以從兩個套件選項中選擇：
+ [**`AWS.Tools`**](#install-aws.tools-on-linux-macos) – 的模組化版本 AWS Tools for PowerShell。每個 AWS 服務都由其個別的小型模組支援，具有共用支援模組 `AWS.Tools.Common`。
+ [**AWSPowerShell.NetCore**](#install-netcore-on-linux-macos) – 的單一大型模組版本 AWS Tools for PowerShell。此單一大型模組支援所有 AWS 服務。
**注意**  
請注意，單一模組可能太大，無法與 [AWS Lambda](https://aws.amazon.com/lambda/) 功能一起使用。請改用上面的模組化版本。

 在執行 Linux 或 macOS 的電腦上設定任何一個都會涉及下列任務，如本主題中稍後部分所說明：

1. 在支援的系統上安裝 PowerShell Core 6.0 或更新版本。

1. 在安裝 PowerShell Core 之後，請在您的系統 shell 中執行 `pwsh` 來啟動 PowerShell。

1. 安裝 `AWS.Tools` 或 AWSPowerShell.NetCore。

1. 執行適當的 `Import-Module` Cmdlet 來將模組匯入您的 PowerShell 工作階段。

1. 執行 [Initialize-AWSDefaultConfiguration](https://docs.aws.amazon.com/powershell/v4/reference/items/Initialize-AWSDefaultConfiguration.html) cmdlet 以提供您的 AWS 登入資料。

## 先決條件
<a name="prerequisites"></a>

若要執行 AWS Tools for PowerShell Core，您的電腦必須執行 PowerShell Core 6.0 或更新版本。
+ 如需支援 Linux 平台的版本清單，以及如何在 Linux 類型電腦上安裝 PowerShell 最新版本的資訊，請參閱 Microsoft 網站上的[在 Linux 上安裝 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux)。有些 Linux 類型作業系統 (例如 Arch、Kali 和 Raspbian) 不受支援，但擁有不同程度的社群支援。
+ 如需支援 macOS 的版本，以及如何在 macOS 上安裝 PowerShell 的資訊，請參閱 Microsoft 網站上的[在 macOS 上安裝 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos)。

## 在 Linux 或 macOS 上安裝 `AWS.Tools`
<a name="install-aws.tools-on-linux-macos"></a>

您可以在執行 PowerShell Core 6.0 或更新版本的電腦 AWS Tools for PowerShell 上安裝 的模組化版本。如需如何安裝 PowerShell Core 的相關資訊，請參閱 Microsoft PwerShell 網站中的《[安裝各種版本的 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell)》一文。

有三種方式可以安裝 `AWS.Tools`：
+ 使用 `AWS.Tools.Installer` 模組中的 Cmdlet。此模組可簡化其他`AWS.Tools`模組的安裝和更新。 `AWS.Tools.Installer`需要 `PowerShellGet`，並會自動下載和安裝其更新版本。 `AWS.Tools.Installer`會自動讓您的模組版本保持同步。當您安裝或更新至某個模組的較新版本時， 中的 cmdlet `AWS.Tools.Installer`會自動將所有其他`AWS.Tools`模組更新為相同的版本。

  此方法會在以下程序中說明。
+ 從 `[AWS.Tools.zip](https://sdk-for-net.amazonwebservices.com/ps/v4/latest/AWS.Tools.zip)` 下載模組，然後解壓縮至其中一個模組目錄。您可以列印 `$Env:PSModulePath` 變數的值來探索您的模組目錄。
+ 使用 `Install-Module` cmdlet 從 PowerShell Gallery 安裝每個服務模組。

**使用 `AWS.Tools.Installer`模組在 Linux 或 macOS `AWS.Tools`上安裝**

1. 執行以下命令來啟動 PowerShell Core 工作階段。

   ```
   $ pwsh
   ```
**注意**  
除非手邊任務需要，否則建議「請勿」**以提高權限的管理員身分執行 PowerShell。這是因為可能會有潛在的安全風險，且不符合最低權限原則。

1. 若要使用 `AWS.Tools.Installer` 安裝模組化 `AWS.Tools` 套件，請執行以下命令。

   ```
   PS > Install-Module -Name AWS.Tools.Installer
   
   Untrusted repository
   You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure
    you want to install the modules from 'PSGallery'?
   [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
   ```

   若您收到通知，顯示儲存庫「不受信任」，表示系統正在詢問您是否無論如何都要進行安裝。輸入 **y** 來允許 PowerShell 安裝模組。若要在不信任儲存庫的情況下避免出現提示及安裝模組，您可以執行以下命令。

   ```
   PS > Install-Module -Name AWS.Tools.Installer -Force
   ```

1. 您現在可以安裝每個您希望使用服務的模組。例如，以下命令會安裝 Amazon EC2 和 Amazon S3 模組。此命令也會安裝指定模組運作所需的任何相依模組。例如，當您安裝第一個 `AWS.Tools` 服務模組時，它也會安裝 `AWS.Tools.Common`。這是所有 AWS 服務模組所需的共用模組。它也會移除舊版模組，並將其他模組更新至相同的更新版本。

   ```
   PS > Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp
   Confirm
   Are you sure you want to perform this action?
     Performing the operation "Install-AWSToolsModule" on target "AWS Tools version 4.0.0.0".
     [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
   
     Installing module AWS.Tools.Common version 4.0.0.0
     Installing module AWS.Tools.EC2 version 4.0.0.0
     Installing module AWS.Tools.Glacier version 4.0.0.0
     Installing module AWS.Tools.S3 version 4.0.0.0
   
     Uninstalling AWS.Tools version 3.3.618.0
     Uninstalling module AWS.Tools.Glacier
     Uninstalling module AWS.Tools.S3
     Uninstalling module AWS.Tools.SimpleNotificationService
     Uninstalling module AWS.Tools.SQS
     Uninstalling module AWS.Tools.Common
   ```
**注意**  
`Install-AWSToolsModule` Cmdlet 會從名為 `PSGallery` 的 `PSRepository` ([https://www.powershellgallery.com/](https://www.powershellgallery.com/)) 下載所有要求的模組，並將儲存庫視為信任的來源。如需此 `PSRepository` 的詳細資訊，請使用 `Get-PSRepository -Name PSGallery` 命令。

   上一個命令會將模組安裝到系統上的預設目錄中。實際的目錄取決於您的作業系統發行版本和版本，以及您安裝的 PowerShell 版本。例如，如果您在類似 RHEL 的系統上安裝 PowerShell 7，則預設模組很可能位於 `/opt/microsoft/powershell/7/Modules` (或 `$PSHOME/Modules`)，而使用者模組很可能位於 `~/.local/share/powershell/Modules`。如需詳細資訊，請參閱 Microsoft PowerShell 網站上的[在 Linux 上安裝 PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux)。若要查看安裝模組的位置，請執行下列命令：

   ```
   PS > Get-Module -ListAvailable
   ```

   若要安裝其他模組，請使用適當的模組名稱執行類似的命令，例如 [PowerShell Gallery](https://www.powershellgallery.com/packages?q=aws) 中的命令。

## 在 Linux 或 macOS 上安裝 AWSPowerShell.NetCore
<a name="install-netcore-on-linux-macos"></a>

若要升級到 AWSPowerShell.NetCore 的較新版本，請遵循 [在 Linux 或 macOS AWS Tools for PowerShell 上更新](#pstools-updating-linux) 中的說明。請先解除安裝舊版 AWSPowerShell.NetCore。

您可以透過下列兩種方式安裝 AWSPowerShell.NetCore：
+ 從 `[AWSPowerShell.NetCore.zip](https://sdk-for-net.amazonwebservices.com/ps/v4/latest/AWSPowerShell.NetCore.zip)` 下載模組，然後解壓縮至其中一個模組目錄。您可以列印 `$Env:PSModulePath` 變數的值來探索您的模組目錄。
+ 使用 `Install-Module` Cmdlet 從 PowerShell Gallery 安裝，如下列程序中所描述。

**使用 Install-Module cmdlet 在 Linux 或 macOS 上安裝 AWSPowerShell.NetCore**

執行以下命令來啟動 PowerShell Core 工作階段。

```
$ pwsh
```

**注意**  
建議「請勿」**執行 `sudo pwsh` 來以提升的管理員權限啟動 PowerShell。這是因為可能會有潛在的安全風險，且不符合最低權限原則。

若要從 PowerShell Gallery 安裝 AWSPowerShell.NetCore 單一模組套件，請執行以下命令。

```
PS > Install-Module -Name AWSPowerShell.NetCore

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure
 you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
```

若您收到通知，顯示儲存庫「不受信任」，表示系統正在詢問您是否無論如何都要進行安裝。輸入 **y** 來允許 PowerShell 安裝模組。若要在不信任儲存庫的情況下避免出現提示，您可以執行以下命令。

```
PS > Install-Module -Name AWSPowerShell.NetCore -Force
```

除非您想要 AWS Tools for PowerShell 為電腦的所有使用者安裝 ，否則您不需要將此命令執行為根。若要執行此作業，請在您以 `sudo pwsh` 啟動的 PowerShell 工作階段中執行以下命令。

```
PS > Install-Module -Scope AllUsers -Name AWSPowerShell.NetCore -Force
```

## 指令碼執行
<a name="enable-script-execution"></a>

`Set-ExecutionPolicy` 命令不適用於非 Windows 系統。您可以執行 `Get-ExecutionPolicy`，這會顯示在非 Windows 系統上執行的 PowerShell Core 的預設執行政策設定是 `Unrestricted`。如需詳細資訊，請參閱 Microsoft Technet 網站上的 [About Execution Policies](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-5.1)。

 由於 `PSModulePath`包含 AWS 模組目錄的位置，因此 `Get-Module -ListAvailable` cmdlet 會顯示您安裝的模組。

**`AWS.Tools`**

```
PS > Get-Module -ListAvailable

    Directory: /Users/username/.local/share/powershell/Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Binary     3.3.563.1  AWS.Tools.Common                    Desk      {Clear-AWSHistory, Set-AWSHistoryConfiguration, Initialize-AWSDefaultConfiguration, Clear-AWSDefaultConfigurat…
```

**AWSPowerShell.NetCore**

```
PS > Get-Module -ListAvailable

Directory: /Users/username/.local/share/powershell/Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     3.3.563.1  AWSPowerShell.NetCore
```

## 設定 PowerShell 主控台以使用 AWS Tools for PowerShell Core （僅限 AWSPowerShell.NetCore)
<a name="pstools-config-ps-window"></a>

PowerShell Core 通常會在您執行模組中的 Cmdlet 時自動載入模組。但這不適用於 AWSPowerShell.NetCore，因為其大小較大。若要開始執行 AWSPowerShell.NetCore Cmdlet，您必須先執行 `Import-Module AWSPowerShell.NetCore` 命令。`AWS.Tools` 模組中的 Cmdlet 不需要此操作。

## 初始化您的 PowerShell 工作階段
<a name="linux-config-init"></a>

當您安裝 之後，在 Linux 型或 macOS 型系統上啟動 PowerShell 時 AWS Tools for PowerShell，必須執行 [Initialize-AWSDefaultConfiguration](https://docs.aws.amazon.com/powershell/v4/reference/items/Initialize-AWSDefaultConfiguration.html) 來指定要使用的 AWS 存取金鑰。如需 `Initialize-AWSDefaultConfiguration` 的相關資訊，請參閱 [使用 AWS 登入資料](specifying-your-aws-credentials.md)。

**注意**  
在舊版 (3.3.96.0 之前） 中 AWS Tools for PowerShell，此 cmdlet 名為 `Initialize-AWSDefaults`。

## 版本控制
<a name="pstools-versioning"></a>

AWS AWS Tools for PowerShell 會定期發行 的新版本，以支援新的 AWS 服務和功能。若要判斷您已安裝的 AWS Tools for PowerShell 版本，請執行 [Get-AWSPowerShellVersion](https://docs.aws.amazon.com/powershell/v4/reference/items/Get-AWSPowerShellVersion.html) cmdlet。

例如：

```
PS > Get-AWSPowerShellVersion

AWS Tools for PowerShell
Version 4.1.849
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Amazon Web Services SDK for .NET
Core Runtime Version 3.7.402.75
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Release notes: https://github.com/aws/aws-tools-for-powershell/blob/v4.1/changelogs/CHANGELOG.ALL.md

This software includes third party software subject to the following copyrights:
- Logging from log4net, Apache License
[http://logging.apache.org/log4net/license.html]
```

若要查看目前版本工具 AWS 中支援服務的清單，請將 `-ListServiceVersionInfo` 參數新增至 [Get-AWSPowerShellVersion](https://docs.aws.amazon.com/powershell/v4/reference/items/Get-AWSPowerShellVersion.html) cmdlet。

若要確認您執行的 PowerShell 版本，請輸入 `$PSVersionTable` 來檢視 `$PSVersionTable` [自動變數](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6)的內容。

例如：

```
PS > $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
```

## 在 Linux 或 macOS AWS Tools for PowerShell 上更新
<a name="pstools-updating-linux"></a>

定期 AWS Tools for PowerShell 發行更新版本的 時，您應該更新在本機執行的版本。

### 更新模組化`AWS.Tools`模組
<a name="update-aws.tools-all-systems"></a>

若要將`AWS.Tools`模組更新至最新版本，請執行下列命令：

```
PS > Update-AWSToolsModule -CleanUp
```

此命令會更新所有目前安裝的 `AWS.Tools` 模組，而對於已成功更新的模組，則會移除舊版。

**注意**  
`Update-AWSToolsModule` Cmdlet 會從名為 `PSGallery` 的 `PSRepository` ([https://www.powershellgallery.com/](https://www.powershellgallery.com/)) 下載所有模組，並視為是信任的來源。如需此 `PSRepository` 的詳細資訊，請使用 `Get-PSRepository -Name PSGallery` 命令。

### 更新 Tools for PowerShell Core
<a name="update-netcore-all-systems"></a>

執行 `Get-AWSPowerShellVersion` Cmdlet 來確認您正在執行的版本，並將此版本與 [PowerShell Gallery](https://www.powershellgallery.com/packages/AWSPowerShell) 網站上可用的 Tools for Windows PowerShell 版本進行比較。我們建議您每兩到三週檢查一次。只有在您更新到具有該支援的版本之後，才能支援新的命令 AWS 和服務。

安裝 AWSPowerShell.NetCore 的較新版本前，請解除安裝現有模組。請在您解除安裝現有套件前關閉任何開啟的 PowerShell 工作階段。執行下列命令以解除安裝套件。

```
PS > Uninstall-Module -Name AWSPowerShell.NetCore -AllVersions
```

解除安裝套件後，請執行以下命令來安裝更新後的模組。

```
PS > Install-Module -Name AWSPowerShell.NetCore
```

安裝完成後，請執行 `Import-Module AWSPowerShell.NetCore` 命令來將更新後的 Cmdlet 載入您的 PowerShell 工作階段。

## 相關資訊
<a name="pstools-seealso-setup"></a>
+  [開始使用 AWS Tools for Windows PowerShell](pstools-getting-started.md) 
+  [在 中使用 AWS 服務 AWS Tools for PowerShell](pstools-using.md) 

# 從 3.3 AWS Tools for PowerShell 版遷移至 第 4 版
<a name="v4migration"></a>

AWS Tools for PowerShell 第 4 版是 3.3 AWS Tools for PowerShell 版的回溯相容更新。此版本新增了大幅改善的項目，同時保持現有的 Cmdlet 行為。

在升級至新版本後，現有指令碼應該能繼續運作，但建議您在升級生產環境前先進行徹底的測試。

本節說明這些變更並解說這些變更可能會對指令碼有何影響。

## 新全面模組化 `AWS.Tools` 版本
<a name="migrate-aws-tools"></a>

AWSPowerShell.NetCore 和 AWSPowerShell 套件為「整合式」。這表示在相同的模組中支援所有 AWS 服務，使其非常龐大，並且隨著新增每個新 AWS 服務和功能而變大。新`AWS.Tools`套件分為較小的模組，可讓您靈活地僅下載和安裝您使用 AWS 的服務所需的套件。此套件包含一個所有其他模組需要的共用 `AWS.Tools.Common` 模組，以及一個可視需要簡化模組安裝、更新及移除作業的 `AWS.Tools.Installer` 模組。

這也會在第一次呼叫時啟用 Cmdlet 的自動匯入功能，而不必先呼叫 `Import-module`。不過，若要在呼叫 Cmdlet 前與相關聯的 .NET 物件進行互動，您仍然必須呼叫 `Import-Module` 以讓 PowerShell 了解相關的 .NET 類型。

例如，以下命令句有 `Amazon.EC2.Model.Filter` 的參照。這種類型的參照無法觸發自動匯入功能，因此您必須先呼叫 `Import-Module`，否則命令則會失敗。

```
PS > $filter = [Amazon.EC2.Model.Filter]@{Name="vpc-id";Values="vpc-1234abcd"}
  InvalidOperation: Unable to find type [Amazon.EC2.Model.Filter].
```

```
PS > Import-Module AWS.Tools.EC2
PS > $filter = [Amazon.EC2.Model.Filter]@{Name="vpc-id";Values="vpc-1234abcd"}
PS > Get-EC2Instance -Filter $filter -Select Reservations.Instances.InstanceId
  i-0123456789abcdefg
  i-0123456789hijklmn
```

## 全新 `Get-AWSService` Cmdlet
<a name="migrate-get-awsservice"></a>

為了協助您探索模組`AWS.Tools`集合中每個 AWS 服務的模組名稱，您可以使用 `Get-AWSService` cmdlet。

```
PS > Get-AWSService
  Service : ACMPCA
  CmdletNounPrefix : PCA
  ModuleName : AWS.Tools.ACMPCA
  SDKAssemblyVersion : 3.3.101.56
  ServiceName : Certificate Manager Private Certificate Authority

  Service : AlexaForBusiness
  CmdletNounPrefix : ALXB
  ModuleName : AWS.Tools.AlexaForBusiness
  SDKAssemblyVersion : 3.3.106.26
  ServiceName : Alexa For Business
  ...
```

## 控制 Cmdlet 傳回之物件的全新 `-Select` 參數
<a name="migrate-select"></a>

第 4 版中的大多數 Cmdlet 可支援全新的 `-Select` 參數。每個 Cmdlet 都會使用 適用於 .NET 的 AWS SDK呼叫 AWS 服務 API。然後， AWS Tools for PowerShell 用戶端會將回應轉換為可在 PowerShell 指令碼和管道中使用的物件，並轉換為其他命令。有時候最終 PowerShell 物件在原始回應中會有比您所需更多的欄位或屬性，有時候您可能會希望物件在回應中包含預設不存在的欄位或屬性。`-Select` 參數可讓您指定 Cmdlet 所傳回之 .NET 物件中要包含的項目。

例如，[Get-S3Object](https://docs.aws.amazon.com/powershell/v4/reference/items/Get-S3Object.html) Cmdlet 會叫用 Amazon S3 開發套件操作 [ListObjects](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/index.html?page=S3/MS3ListObjectsListObjectsRequest.html)。該操作會傳回 [ListObjectsResponse](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/index.html?page=S3/MS3ListObjectsListObjectsRequest.h) 物件。不過，根據預設，`Get-S3Object` Cmdlet 只會將開發套件回應的 `S3Objects` 元素傳回給 PowerShell 使用者。在以下範例中，該物件是具有兩個元素的陣列。

```
PS > Get-S3Object -BucketName amzn-s3-demo-bucket

ETag : "01234567890123456789012345678901111"
BucketName : amzn-s3-demo-bucket
Key : file1.txt
LastModified : 9/30/2019 1:31:40 PM
Owner : Amazon.S3.Model.Owner
Size : 568
StorageClass : STANDARD

ETag : "01234567890123456789012345678902222"
BucketName : amzn-s3-demo-bucket
Key : file2.txt
LastModified : 7/15/2019 9:36:54 AM
Owner : Amazon.S3.Model.Owner
Size : 392
StorageClass : STANDARD
```

在 AWS Tools for PowerShell 版本 4 中，您可以指定 `-Select *`傳回 SDK API 呼叫傳回的完整 .NET 回應物件。

```
PS > Get-S3Object -BucketName amzn-s3-demo-bucket -Select *
  IsTruncated    : False
  NextMarker     :
  S3Objects      : {file1.txt, file2.txt}
  Name           : amzn-s3-demo-bucket
  Prefix         :
  MaxKeys        : 1000
  CommonPrefixes : {}
  Delimiter      :
```

您也可以指定您想要的特定巢狀屬性的路徑。以下範例只會傳回 `S3Objects` 陣列中每個元素的 `Key` 屬性。

```
PS > Get-S3Object -BucketName amzn-s3-demo-bucket -Select S3Objects.Key
file1.txt
file2.txt
```

在某些情況下，傳回 Cmdlet 參數可能非常有用。您可以使用 `-Select ^ParameterName` 來達成此操作。此功能取代了 `-PassThru` 參數，該參數仍可取得但已遭取代。

```
PS > Get-S3Object -BucketName amzn-s3-demo-bucket -Select S3Objects.Key |
>> Write-S3ObjectTagSet -Select ^Key -BucketName amzn-s3-demo-bucket -Tagging_TagSet @{ Key='key'; Value='value'}
  file1.txt
  file2.txt
```

每個 Cmdlet 的[參考主題](https://docs.aws.amazon.com/powershell/v4/reference/)會識別是否支援 `-Select` 參數。

## 以更一致的方式限制輸出的項目數
<a name="migrate-iterate"></a>

舊版 AWS Tools for PowerShell 可讓您使用 `-MaxItems` 參數來指定最終輸出中傳回的物件數量上限。

`AWS.Tools` 已移除此行為。

在 AWSPowerShell.NetCore 和 AWSPowerShell 中，此行為已遭取代，而未來版本也會移除此行為。

如果基礎服務 API 支援 `MaxItems` 參數，則仍可依 API 指定取得及運作，但不會再有限制 Cmdlet 輸出中傳回之項目數的新增行為。

若要限制最終輸出中傳回的項目數，請將輸出輸送至 `Select-Object` Cmdlet 並指定 `-First n` 參數，其中 *n* 是要在最終輸出中包含的項目數上限。

```
PS > Get-S3ObjectV2 -BucketName amzn-s3-demo-bucket -Select S3Objects.Key | select -first 2
file1.txt
file2.txt
```

並非所有 AWS 服務`-MaxItems`都以相同的方式支援，因此這會移除該不一致的情況，以及有時發生的非預期結果。此外結合新 [`-Select`](#migrate-select) 參數的 `-MaxItems` 有時可能會導致令人混淆的結果。

## 更易於使用的串流參數
<a name="migrate-streamparam"></a>

`Stream` 或 `byte[]` 類型的參數現在可以接受 `string`、`string[]` 或 `FileInfo` 值。

例如，您可以使用以下任一範例。

```
PS > Invoke-LMFunction -FunctionName MyTestFunction -PayloadStream '{
>> "some": "json"
>> }'
```

```
PS > Invoke-LMFunction -FunctionName MyTestFunction -PayloadStream (ls .\some.json)
```

```
PS > Invoke-LMFunction -FunctionName MyTestFunction -PayloadStream @('{', '"some": "json"', '}')
```

 AWS Tools for PowerShell `byte[]`會使用 UTF-8 編碼將所有字串轉換為 。

## 依屬性名稱擴充管道
<a name="migrate-pipes"></a>

為了提升使用者體驗的一致性，您現在可以指定「任何」**參數的屬性名稱，藉此傳遞管道輸入。

在以下範例中，我們建立了一個自訂物件，其屬性具有符合目標 Cmdlet 參數名稱的名稱。當 Cmdlet 執行時，它會自動使用這些屬性做為其參數。

```
PS > [pscustomobject] @{ BucketName='amzn-s3-demo-bucket'; Key='file1.txt'; PartNumber=1 } | Get-S3ObjectMetadata
```

**注意**  
有些屬性在舊版 中支援此屬性 AWS Tools for PowerShell。第 4 版可讓您指定「所有」**參數，讓此體驗更加一致。

## 靜態常見參數
<a name="migrate-staticcommonparams"></a>

為了改善 4.0 版的一致性 AWS Tools for PowerShell，所有參數都是靜態的。

在舊版 中 AWS Tools for PowerShell，一些常見的參數，例如 `AccessKey``SecretKey`、`ProfileName`、 或 `Region`是[動態](https://docs.microsoft.com/dotnet/api/system.management.automation.idynamicparameters)的，而所有其他參數都是靜態的。這可能會發生問題，因為 PowerShell 會先繫結靜態參數，然後再繫結動態參數。例如，假設您執行以下命令。

```
PS > Get-EC2Region -Region us-west-2
```

舊版 PowerShell 會將 `us-west-2` 值繫結至 `-RegionName` 靜態參數，而不是 `-Region` 動態參數。這可能會讓使用者產生混淆。

## `AWS.Tools` 會宣告並強制執行必要參數
<a name="migrate-mandatoryparams"></a>

`AWS.Tools.*` 模組現在會宣告並強制執行必要的 Cmdlet 參數。當 AWS 服務宣告某個 API 參數為必要時，如果您尚未指定該參數，PowerShell 則會提示您對應的 Cmdlet 參數。這僅適用於 `AWS.Tools`。為確保回溯相容性，這不適用於 AWSPowerShell.NetCore 或 AWSPowerShell。

## 所有參數皆可為 Null
<a name="migrate-nullableparams"></a>

您現在可以將 `$null` 指派給值類型參數 (數字和日期)。此變更應該不會影響現有的指令碼。這可讓您略過必要參數的提示。必要參數只會在 `AWS.Tools` 中強制執行。

如果您使用第 4 版執行以下範例，則會有效略過用戶端驗證，因為您會為每個必要參數提供「值」。不過，Amazon EC2 API 服務呼叫會失敗，因為 AWS 服務仍然需要該資訊。

```
PS > Get-EC2InstanceAttribute -InstanceId $null -Attribute $null
WARNING: You are passing $null as a value for parameter Attribute which is marked as required.
In case you believe this parameter was incorrectly marked as required, report this by opening 
an issue at [https://github.com/aws/aws-tools-for-powershell/issues](https://github.com/aws/aws-tools-for-powershell/issues).
WARNING: You are passing $null as a value for parameter InstanceId which is marked as required.
In case you believe this parameter was incorrectly marked as required, report this by opening
an issue at [https://github.com/aws/aws-tools-for-powershell/issues](https://github.com/aws/aws-tools-for-powershell/issues).

Get-EC2InstanceAttribute : The request must contain the parameter instanceId
```

## 移除先前取代的功能
<a name="migrate-removeprevdeprecated"></a>

下列功能已在舊版 中棄用 AWS Tools for PowerShell ，並已在版本 4 中移除：
+ 移除 `Stop-EC2Instance` Cmdlet 中的 `-Terminate` 參數。請改用 `Remove-EC2Instance`。
+ 移除 Clear-AWSCredential Cmdlet 中的 `-ProfileName` 參數。請改用 `Remove-AWSCredentialProfile`。
+ 移除 `Import-EC2Instance` 和 `Import-EC2Volume` Cmdlet。