

第 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)

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

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

如需預先安裝在 上的 Tools for PowerShell 的相關資訊 AWS CloudShell，請參閱 [在 CloudShell 上安裝](pstools-getting-set-up-cloudshell.md)。

若要 AWS Tools for PowerShell 在 Linux 或 macOS 電腦上安裝 ，您可以從兩個套件選項中選擇：
+ [**`AWS.Tools`**](install-aws.tools-on-linux-macos.md) – 的模組化版本 AWS Tools for PowerShell。每個 AWS 服務都由其個別的小型模組支援，具有共用支援模組 `AWS.Tools.Common`。
+ [**AWSPowerShell.NetCore**](install-netcore-on-linux-macos.md) – 的單一大型模組版本 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/v5/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)。

**Topics**
+ [先決條件](#prerequisites)
+ [安裝 `AWS.Tools`（建議）](install-aws.tools-on-linux-macos.md)
+ [安裝 AWSPowerShell.NetCore](install-netcore-on-linux-macos.md)

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

如需 AWS Tools for PowerShell 在 Linux 或 macOS 上安裝 的一般資訊，包括先決條件和其他選項，請參閱[父主題](pstools-getting-set-up-linux-mac.md)。

如需預先安裝在 上的 Tools for PowerShell 的相關資訊 AWS CloudShell，請參閱 [在 CloudShell 上安裝](pstools-getting-set-up-cloudshell.md)。

您可以在執行 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/v5/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) 中的命令。

## 指令碼執行
<a name="enable-script-execution-aws-tools"></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…
```

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

當您安裝 之後，在 Linux 型或 macOS 型系統上啟動 PowerShell 時 AWS Tools for PowerShell，必須執行 [Initialize-AWSDefaultConfiguration](https://docs.aws.amazon.com/powershell/v5/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-aws-tools"></a>

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

例如：

```
PS > Get-AWSPowerShellVersion

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

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

Release notes: https://github.com/aws/aws-tools-for-powershell/blob/main/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/v5/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-aws-tools"></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/)) 下載所有模組，並視為是信任的來源。如需此 的詳細資訊，請使用 `Get-PSRepository -Name PSGallery`命令`PSRepository`。

## 相關資訊
<a name="pstools-seealso-setup-aws-tools"></a>
+  [設定和使用 AWS Tools for PowerShell](pstools-getting-started.md) 
+  [在 中呼叫 AWS 服務 AWS Tools for PowerShell](pstools-using.md) 

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

如需 AWS Tools for PowerShell 在 Linux 或 macOS 上安裝 的一般資訊，包括先決條件和其他選項，請參閱[父主題](pstools-getting-set-up-linux-mac.md)。

如需預先安裝在 上的 Tools for PowerShell 的相關資訊 AWS CloudShell，請參閱 [在 CloudShell 上安裝](pstools-getting-set-up-cloudshell.md)。

**注意**  
AWSPowerShell.NetCore 不是安裝 的建議方法 AWS Tools for PowerShell。如需建議的方法，請[安裝 `AWS.Tools`（建議）](install-aws.tools-on-linux-macos.md)改為參閱 。

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

您可以透過下列兩種方式安裝 AWSPowerShell.NetCore：
+ 從 `[AWSPowerShell.NetCore.zip](https://sdk-for-net.amazonwebservices.com/ps/v5/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-netcore"></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 會顯示您安裝的模組。

**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-netcore"></a>

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

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

當您安裝 之後，在 Linux 型或 macOS 型系統上啟動 PowerShell 時 AWS Tools for PowerShell，必須執行 [Initialize-AWSDefaultConfiguration](https://docs.aws.amazon.com/powershell/v5/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-netcore"></a>

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

例如：

```
PS > Get-AWSPowerShellVersion

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

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

Release notes: https://github.com/aws/aws-tools-for-powershell/blob/main/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/v5/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-netcore"></a>

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

### 更新 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-netcore"></a>
+  [設定和使用 AWS Tools for PowerShell](pstools-getting-started.md) 
+  [在 中呼叫 AWS 服務 AWS Tools for PowerShell](pstools-using.md) 