

的版本 5 (V5) Amazon Tools for PowerShell 已经发布！

有关重大更改和迁移应用程序的信息，请参阅[迁移主题](https://docs.amazonaws.cn/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.amazonaws.cn/powershell/v5/userguide/migrating-v5.html](https://docs.amazonaws.cn/powershell/v5/userguide/migrating-v5.html)

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

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

有关上预安装 PowerShell 的工具的信息 Amazon CloudShell，请参阅[已安装在 CloudShell](pstools-getting-set-up-cloudshell.md)。

基于 Windows 的计算机可以运行任何 Amazon Tools for PowerShell 软件包选项：
+ [**`AWS.Tools`**](ps-installing-awstools.md)-的模块化版本。 Amazon Tools for PowerShell每项 Amazon 服务都由其自己的独立小型模块提供支持，并带有共享的支持模块`AWS.Tools.Common`和`AWS.Tools.Installer`。
+ [**AWSPower壳牌。 NetCore**](ps-installing-awspowershellnetcore.md)-的单一大模块版本。 Amazon Tools for PowerShell这个单一的大型模块支持所有 Amazon 服务。
**注意**  
请注意，单个模块可能太大，无法与 [Amazon Lambda](https://www.amazonaws.cn/lambda/) 函数一起使用。请改用上面显示的模块化版本。
+ [**AWSPowerShell**](ps-installing-awswindowspowershell.md)-传统的、特定于 Windows 的、单一的大模块版本。 Amazon Tools for PowerShell这个单一的大型模块支持所有 Amazon 服务。

你选择的软件包取决于你所运行的 Windows 的版本和版本。

**注意**  
默认情况下， Amazon Tools for PowerShell 它们会安装在所有基于 Windows 的 Amazon 系统映像上 () AMIs。安装的选项取决于 AMI。许多 AMIs 都有 AWSPower Shell 模块，但有些可能有不同的选择。例如，适用于 Windows Server 2025 的亚马逊 EC2 AMIs 使用模块化`AWS.Tools`选项。

设置 Amazon Tools for PowerShell 涉及以下高级任务，后续主题将详细介绍这些任务。

1. 安装适合您环境的 Amazon Tools for PowerShell 软件包选项。

1. 通过运行 `Get-ExecutionPolicy` cmdlet 验证是否已启用脚本执行。

1. 将 Amazon Tools for PowerShell 模块导入您的 PowerShell 会话。

## 先决条件
<a name="prerequisites"></a>

包括 PowerShell 酷睿 PowerShell在内的较新版本可在微软网站上[安装各种版本 PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell)上从微软下载。

**Topics**
+ [先决条件](#prerequisites)
+ [安装`AWS.Tools`（推荐）](ps-installing-awstools.md)
+ [安装 AWSPower外壳。 NetCore](ps-installing-awspowershellnetcore.md)
+ [安装 AWSPower外壳（旧版）](ps-installing-awswindowspowershell.md)

# `AWS.Tools`在 Windows 上安装（推荐）
<a name="ps-installing-awstools"></a>

有关 Amazon Tools for PowerShell 在 Windows 上安装的一般信息，包括先决条件和其他选项，请参阅[父主题](pstools-getting-set-up-windows.md)。

有关上预安装 PowerShell 的工具的信息 Amazon CloudShell，请参阅[已安装在 CloudShell](pstools-getting-set-up-cloudshell.md)。

你可以在运行 Windows PowerShell 5.1、 PowerShell 酷睿 6.0 或更高版本的 Windows 的计算机 Amazon Tools for PowerShell 上安装模块化版本。有关如何安装 PowerShell Core 的信息，请参阅 PowerShell在 Microsoft 网站上[安装各种版本](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` 会自动保持您的模块版本同步。当您安装或更新到一个模块的较新版本时，`AWS.Tools.Installer` 中的 cmdlet 会自动将所有其他 `AWS.Tools` 模块更新为同一版本。

  该方法在以下过程中描述。
+ 从 `[AWS.Tools.zip](https://sdk-for-net.amazonwebservices.com/ps/v5/latest/AWS.Tools.zip)` 下载模块并将它们提取到其中一个模块文件夹中。您可以通过显示 `PSModulePath` 变量的值来查找模块文件夹。
**警告**  
下载 ZIP 文件后并在提取内容之前，您可能需要将其解除锁定。通常，通过打开文件的属性，查看**常规**选项卡，并选择**解除锁定**复选框（如果存在）即可完成这一操作。  
如果 ZIP 文件需要解除锁定但您没有这样做，您可能会收到类似这样的错误：“Import-Module : 无法加载文件或程序集”。
+ 使用 `Install-Module` cmdlet 从 PowerShell 库中安装每个服务模块。

**使用 `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 为要使用的每项 Amazon 服务安装该模块。例如，以下命令将安装 Amazon EC2 和 Amazon S3 模块。此命令还会安装指定模块工作所需的任何依赖模块。例如，当您安装第一个 `AWS.Tools` 服务模块时，它还会安装 `AWS.Tools.Common`。这是所有 Amazon 服务模块都需要的共享模块。它还会删除模块的较早版本，并将其他模块更新到相同的较新版本。

   ```
   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 从`PSRepository`命名 `PSGallery` ([https://www.powershellgallery.com/](https://www.powershellgallery.com/)) 下载所有请求的模块，并将其视为可信来源。有关此 `PSRepository` 的更多信息，请使用命令 `Get-PSRepository -Name PSGallery`。

   默认情况下，前面的命令会将模块安装到 `%USERPROFILE%\Documents\WindowsPowerShell\Modules` 文件夹中。要 Amazon Tools for PowerShell 为计算机的所有用户安装，必须在以管理员身份启动的 PowerShell 会话中运行以下命令。例如，以下命令将 IAM 模块安装到所有用户均可访问的 `%ProgramFiles%\WindowsPowerShell\Modules` 文件夹中。

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

   要安装其他模块，请使用相应的模块名称运行类似的命令，如图[PowerShell 库中所示](https://www.powershellgallery.com/packages?q=aws)。

## 启用脚本执行
<a name="enable-script-execution-aws-tools"></a>

要加载 Amazon Tools for PowerShell 模块，必须启用 PowerShell 脚本执行。要启用脚本执行，请运行 `Set-ExecutionPolicy` cmdlet 以设置 `RemoteSigned` 策略。有关更多信息，请参阅 Microsoft Technet 网站上的[关于执行策略](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies)。

**注意**  
此要求仅适用于运行 Windows 的计算机。`ExecutionPolicy` 安全限制不存在于其他操作系统上。

 **启用脚本执行** 

1. 需要管理员权限才能设置执行策略。如果您不是以具有管理员权限的用户身份登录，请以管理员身份打开 PowerShell 会话。选择**开始**，然后选择**所有程序**。选择 “**附件**”，然后选择 “**Windows**” PowerShell。右键单击 **Windows PowerShell**，然后在上下文菜单上选择 “**以管理员身份运行**”。

1. 在命令提示符处，输入以下命令。

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

**注意**  
在 64 位系统上，对于 32 位版本的 **Windows PowerShell (x** 86) PowerShell，必须单独执行此操作。

如果您没有正确设置执行策略，则每当您尝试运行脚本（例如您的配置文件）时，都会 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
```

适用于 Windows 的工具 PowerShell 安装程序会自动更新[PSModule路径](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath)，以包括包含该`AWSPowerShell`模块的目录的位置。

由于`PSModulePath`包含 Amazon 模块目录的位置，因此 `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-aws-tools"></a>

Amazon Amazon Tools for PowerShell 定期发布新版本以支持新的 Amazon 服务和功能。要确定已安装的工具的版本，请运行 [Get-AWSPower ShellVersion](https://docs.amazonaws.cn/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]
```

您也可以将`-ListServiceVersionInfo`参数添加到 [Get-AWSPower ShellVersion](https://docs.amazonaws.cn/powershell/v5/reference/items/Get-AWSPowerShellVersion.html) 命令中，以查看当前版本的工具支持的 Amazon 服务列表。如果使用模块化 `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`请输入查看 \$1 T PSVersion able [自动变](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
```

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

随着更新版本的 Amazon Tools for PowerShell 发布，您应该定期更新在本地运行的版本。

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

要将 `AWS.Tools` 模块更新到最新版本，请运行以下命令：

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

此命令更新当前安装的所有`AWS.Tools`模块，并在成功更新后删除早期版本。

**注意**  
`Update-AWSToolsModule`cmdlet 从`PSRepository`命名的 `PSGallery` ([https://www.powershellgallery.com/](https://www.powershellgallery.com/)) 下载所有模块，并将其视为可信来源。使用`Get-PSRepository -Name PSGallery`命令获取有关此内容的更多信息`PSRepository`。

# 安装 AWSPower外壳。 NetCore 在 Windows 上
<a name="ps-installing-awspowershellnetcore"></a>

有关 Amazon Tools for PowerShell 在 Windows 上安装的一般信息，包括先决条件和其他选项，请参阅[父主题](pstools-getting-set-up-windows.md)。

有关上预安装 PowerShell 的工具的信息 Amazon CloudShell，请参阅[已安装在 CloudShell](pstools-getting-set-up-cloudshell.md)。

**注意**  
AWSPower壳牌。 NetCore 不是安装的推荐方法 Amazon Tools for PowerShell。有关推荐的方法，请参[安装`AWS.Tools`（推荐）](ps-installing-awstools.md)阅。

你可以安装 AWSPower命令行管理程序。 NetCore 在运行 Windows PowerShell 版本 3 至 5.1 或 PowerShell 酷睿 6.0 或更高版本的计算机上。有关如何安装 PowerShell Core 的信息，请参阅 Microsoft PowerShell 网站上[安装各种版本](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell)的。 PowerShell

你可以安装 AWSPower命令行管理程序。 NetCore 有两种方式之一
+ 从[AWSPower命令行管理程序下载模块。 NetCore.zip](https://sdk-for-net.amazonwebservices.com/ps/v5/latest/AWSPowerShell.NetCore.zip) 并将其解压缩到其中一个模块目录中。您可以通过显示 `PSModulePath` 变量的值来查找模块目录。
**警告**  
下载 ZIP 文件后，在解压缩内容之前，可能需要将其解除封锁。这通常是通过打开文件属性，查看 “**常规**” 选项卡，然后选择 “**取消阻止**” 复选框（如果存在）来完成的。  
如果 ZIP 文件需要解除阻止，但您没有这样做，则可能会收到类似以下内容的错误：“导入模块：无法加载文件或程序集”。
+ 使用 `Install-Module` cmdlet 从 PowerShell 库中安装，如以下过程所述。

**安装 AWSPower命令行管理程序。 NetCore 使用 Install-Module cmdlet 从 PowerShell 图库**中获取

安装 AWSPower命令行管理程序。 NetCore 在 PowerShell 图库中，您的计算机必须运行的是 PowerShell 5.0 或更高版本，或者[PowerShellGet](https://www.powershellgallery.com/packages/PowerShellGet)在 PowerShell 3 或更高版本上运行。运行以下命令。

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

如果您以管理员 PowerShell 身份运行，则会 Amazon Tools for PowerShell 为计算机上的所有用户安装前面的命令。如果您以没有管理员权限的标准用户 PowerShell 身份运行，则仅 Amazon Tools for PowerShell 为当前用户安装相同的命令。

要仅在当前用户具有管理员权限时为该用户安装，请按以下步骤带有 `-Scope CurrentUser` 参数集运行此命令。

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

尽管 PowerShell 3.0 及更高版本通常会在您第一次在模块（命令行管理程序）中运行 cmdlet 时将模块加载到您的 PowerShell 会话中。 AWSPower NetCore 模块太大，无法支持此功能。您必须改为显式加载 AWSPower命令行管理程序。 NetCore 通过运行以下命令将核心模块添加到您的 PowerShell 会话中。

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

加载外 AWSPower壳。 NetCore 自动进入会 PowerShell 话，将该命令添加到您的 PowerShell 配置文件中。有关编辑个人 PowerShell 资料的更多信息，请参阅文档中的[关于配置](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_profiles) PowerShell 文件。

## 启用脚本执行
<a name="enable-script-execution-ps-core"></a>

要加载 Amazon Tools for PowerShell 模块，必须启用 PowerShell 脚本执行。要启用脚本执行，请运行 `Set-ExecutionPolicy` cmdlet 以设置 `RemoteSigned` 策略。有关更多信息，请参阅 Microsoft Technet 网站上的[关于执行策略](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies)。

**注意**  
此要求仅适用于运行 Windows 的计算机。`ExecutionPolicy` 安全限制不存在于其他操作系统上。

 **启用脚本执行** 

1. 需要管理员权限才能设置执行策略。如果您不是以具有管理员权限的用户身份登录，请以管理员身份打开 PowerShell 会话。选择**开始**，然后选择**所有程序**。选择 “**附件**”，然后选择 “**Windows**” PowerShell。右键单击 **Windows PowerShell**，然后在上下文菜单上选择 “**以管理员身份运行**”。

1. 在命令提示符处，输入以下命令。

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

**注意**  
在 64 位系统上，对于 32 位版本的 **Windows PowerShell (x** 86) PowerShell，必须单独执行此操作。

如果您没有正确设置执行策略，则每当您尝试运行脚本（例如您的配置文件）时，都会 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
```

适用于 Windows 的工具 PowerShell 安装程序会自动更新[PSModule路径](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath)，以包括包含该`AWSPowerShell`模块的目录的位置。

由于`PSModulePath`包含 Amazon 模块目录的位置，因此 `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-ps-core"></a>

Amazon Amazon Tools for PowerShell 定期发布新版本以支持新的 Amazon 服务和功能。要确定已安装的工具的版本，请运行 [Get-AWSPower ShellVersion](https://docs.amazonaws.cn/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]
```

您也可以将`-ListServiceVersionInfo`参数添加到 [Get-AWSPower ShellVersion](https://docs.amazonaws.cn/powershell/v5/reference/items/Get-AWSPowerShellVersion.html) 命令中，以查看当前版本的工具支持的 Amazon 服务列表。如果使用模块化 `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`请输入查看 \$1 T PSVersion able [自动变](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
```

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

随着更新版本的 Amazon Tools for PowerShell 发布，您应该定期更新在本地运行的版本。

### 更新 PowerShell 核心工具
<a name="update-the-tools-for-powershell-core"></a>

运行 `Get-AWSPowerShellVersion` cmdlet 以确定你正在运行的版本，并将其与[PowerShell 图库](https://www.powershellgallery.com/packages/AWSPowerShell)网站上提供的适用于 Windows PowerShell 的工具版本进行比较。我们建议您每两到三个星期检查一次。只有在更新到支持新命令和 Amazon 服务的版本后，才会提供对新命令和服务的支持。

在安装更新版本的 AWSPower Shell 之前。 NetCore，卸载现有模块。在卸载现有软件包之前，请关闭所有打开的 PowerShell 会话。运行以下命令来卸载该程序包。

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

在卸载程序包后，通过运行以下命令来安装更新的模块。

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

安装完成后，运行命令将更新后的 cmdlet 加载`Import-Module AWSPowerShell.NetCore`到您的 PowerShell 会话中。

# 在 Windows 上安装 AWSPower Shell PowerShell （旧版）
<a name="ps-installing-awswindowspowershell"></a>

有关 Amazon Tools for PowerShell 在 Windows 上安装的一般信息，包括先决条件和其他选项，请参阅[父主题](pstools-getting-set-up-windows.md)。

有关上预安装 PowerShell 的工具的信息 Amazon CloudShell，请参阅[已安装在 CloudShell](pstools-getting-set-up-cloudshell.md)。

**注意**  
AWSPower建议不要使用 Shell 来安装 Amazon Tools for PowerShell。有关推荐的方法，请参[安装`AWS.Tools`（推荐）](ps-installing-awstools.md)阅。

您可以通过以下两种 Amazon Tools for Windows PowerShell 方式之一进行安装：
+ 从 [AWSPowerShell.zip](https://sdk-for-net.amazonwebservices.com/ps/v5/latest/AWSPowerShell.zip) 下载模块并将其解压缩到其中一个模块目录中。您可以通过显示 `PSModulePath` 变量的值来查找模块目录。
**警告**  
下载 ZIP 文件后并在提取内容之前，您可能需要将其解除锁定。通常，通过打开文件的属性，查看**常规**选项卡，并选择**解除锁定**复选框（如果存在）即可完成这一操作。  
如果 ZIP 文件需要解除锁定但您没有这样做，您可能会收到类似这样的错误：“Import-Module : 无法加载文件或程序集”。
+ 按照以下步骤所述，使用 `Install-Module` cmdlet 从 PowerShell 库中安装。

**使用 Install-Module cmdlet 从 PowerShell 库中安装 AWSPower Shell**

如果您运行的是 PowerShell 5.0 或更高版本，或者已在 PowerShell 3 或更高版本[PowerShellGet](https://www.powershellgallery.com/packages/PowerShellGet)上安装 AWSPower命令行管理程序，则可以从 PowerShell 库中安装命令行管理程序。你可以通过运行以下 AWSPower命令从 Microsoft 的[PowerShell图库](https://www.powershellgallery.com/packages/AWSPowerShell)中安装和更新 Shell。

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

要将 AWSPower命令行管理程序模块自动加载到 PowerShell 会话中，请将之前的 `import-module` cmdlet 添加到您的 PowerShell 配置文件中。有关编辑个人 PowerShell 资料的更多信息，请参阅文档中的[关于配置](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-6) PowerShell 文件。

## 启用脚本执行
<a name="enable-script-execution-windows-ps"></a>

要加载 Amazon Tools for PowerShell 模块，必须启用 PowerShell 脚本执行。要启用脚本执行，请运行 `Set-ExecutionPolicy` cmdlet 以设置 `RemoteSigned` 策略。有关更多信息，请参阅 Microsoft Technet 网站上的[关于执行策略](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies)。

**注意**  
此要求仅适用于运行 Windows 的计算机。`ExecutionPolicy` 安全限制不存在于其他操作系统上。

 **启用脚本执行** 

1. 需要管理员权限才能设置执行策略。如果您不是以具有管理员权限的用户身份登录，请以管理员身份打开 PowerShell 会话。选择**开始**，然后选择**所有程序**。选择 “**附件**”，然后选择 “**Windows**” PowerShell。右键单击 **Windows PowerShell**，然后在上下文菜单上选择 “**以管理员身份运行**”。

1. 在命令提示符处，输入以下命令。

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

**注意**  
在 64 位系统上，对于 32 位版本的 **Windows PowerShell (x** 86) PowerShell，必须单独执行此操作。

如果您没有正确设置执行策略，则每当您尝试运行脚本（例如您的配置文件）时，都会 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
```

适用于 Windows 的工具 PowerShell 安装程序会自动更新[PSModule路径](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath)，以包括包含该`AWSPowerShell`模块的目录的位置。

由于`PSModulePath`包含 Amazon 模块目录的位置，因此 `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-windows-ps"></a>

Amazon Amazon Tools for PowerShell 定期发布新版本以支持新的 Amazon 服务和功能。要确定已安装的工具的版本，请运行 [Get-AWSPower ShellVersion](https://docs.amazonaws.cn/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]
```

您也可以将`-ListServiceVersionInfo`参数添加到 [Get-AWSPower ShellVersion](https://docs.amazonaws.cn/powershell/v5/reference/items/Get-AWSPowerShellVersion.html) 命令中，以查看当前版本的工具支持的 Amazon 服务列表。如果使用模块化 `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`请输入查看 \$1 T PSVersion able [自动变](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
```

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

随着更新版本的 Amazon Tools for PowerShell 发布，您应该定期更新在本地运行的版本。

### 更新适用于 Windows 的工具 PowerShell
<a name="update-the-tools-for-windows-powershell"></a>

运行 `Get-AWSPowerShellVersion` cmdlet 以确定你正在运行的版本，并将其与[PowerShell 图库](https://www.powershellgallery.com/packages/AWSPowerShell)网站上提供的适用于 Windows PowerShell 的工具版本进行比较。我们建议您每两到三个星期检查一次。只有在更新到支持新命令和 Amazon 服务的版本后，才会提供对新命令和服务的支持。
+ 如果使用 `Install-Module` cmdlet 进行了安装，请运行以下命令。

  ```
  PS > Uninstall-Module -Name AWSPowerShell -AllVersions
  PS > Install-Module -Name AWSPowerShell
  ```
+ 如果您已使用下载的 ZIP 文件进行安装：

  1. 从 “[工具](https://www.amazonaws.cn/powershell/)” PowerShell 网站下载最新版本。将下载的文件名中的程序包版本号与运行 `Get-AWSPowerShellVersion` cmdlet 时获得的版本号进行比较。

  1. 如果下载的版本高于你已安装的版本，请关闭所有适用于 Windows PowerShell 控制台的工具。

  1. 安装适用于 Windows 的工具的更新版本 PowerShell。

安装完成后，运行`Import-Module AWSPowerShell`将更新后的 cmdlet 加载到您的 PowerShell 会话中。或者从 “**开始**” 菜单运行自定义 Amazon Tools for PowerShell 控制台。