AWS Tools for PowerShell 在視窗上安裝 - AWS Tools for PowerShell

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

AWS Tools for PowerShell 在視窗上安裝

以 Windows 為基礎的電腦可以執行下列任何 AWS Tools for PowerShell 套件選項:

  • AWS.Tools-的模組化版本。 AWS Tools for PowerShell每個 AWS 服務都由自己的個人小模塊支持,並具有共享的支持模塊AWS.Tools.CommonAWS.Tools.Installer.

  • AWSPowerShell。 NetCore-單一、大型模組版本的 AWS Tools for PowerShell. 這個單一的大型模組支援所有 AWS 服務。

    注意

    請注意,單一模組可能太大,無法與 AWS Lambda 功能一起使用。請改用上面的模組化版本。

  • AWSPowerShell - AWS Tools for PowerShell的舊版 Windows 專用、單一、大型模組版本。這個單一的大型模組支援所有 AWS 服務。

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

注意

默認情況下,Windows 工具 PowerShell (AWSPowerShell 模塊)安裝在所有基於 Windows 的 Amazon 機器映像(AMI)上。

設定 AWS Tools for PowerShell 包含下列高階工作,在本主題中詳細說明。

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

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

  3. 將 AWS Tools for PowerShell 模組匯入您的 PowerShell 工作階段。

必要條件

較新版本的 PowerShell,包括 PowerShell 核心,可作為下載從 Microsoft 在微軟的網站 PowerShell上安裝各種版本

在 Windows 上安裝 AWS.Tools

您可以在執行視窗 PowerShell 5.1 或 PowerShell 核心 6.0 或更新版本的電腦 AWS Tools for PowerShell 上安裝模組化版本。如需有關如何安裝 PowerShell核心的詳細資訊,請參閱 PowerShell在 Microsoft 網站上安裝各種版本的

有三種方式可以安裝 AWS.Tools

  • 使用 AWS.Tools.Installer 模組中的 Cmdlet。該模塊簡化了其他模AWS.Tools塊的安裝和更新。 AWS.Tools.Installer需要PowerShellGet,並自動下載並安裝它的更新版本。 AWS.Tools.Installer自動保持您的模塊版本同步。當您安裝或更新至某個模組的較新版本時,中的指令程式AWS.Tools.Installer會自動將所有其他AWS.Tools模組更新為相同版本。

    此方法會在下列程序中說明。

  • AWS.Tools.zip 下載模組,然後解壓縮至其中一個模組資料夾。您可以顯示 PSModulePath 環境變數的值來探索自己的模組資料夾。

  • 使用Install-Module指令程式從程式 PowerShell 庫安裝每個服務模組。

若要使用該AWS.Tools.Installer模組AWS.Tools在視窗上安裝
  1. 啟動 PowerShell 工作階段。

    注意

    我們建議您要 PowerShell 以具有提升權限的系統管理員身分執行,除非手頭的工作需要。這是因為可能會有潛在的安全風險,且不符合最低權限原則。

  2. 若要安裝模組化 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
  3. 您現在可以使用Install-AWSToolsModule指令程式,針對要使用的每個 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 會從名為 PSGalleryPSRepository (https://www.powershellgallery.com/) 下載所有要求的模組,並視為是信任的來源。如需此 PSRepository 的詳細資訊,請使用 Get-PSRepository -Name PSGallery 命令。

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

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

    要安裝其他模塊,請使用相應的模塊名稱運行類似的命令,如PowerShell 圖庫中所找到的。

安裝 AWSPowerShell。 NetCore 在視窗上

您可以安裝 AWSPowerShell. NetCore 在執行 Windows PowerShell 版本 3 到 5.1 或 PowerShell 核心 6.0 或更新版本的電腦上。如需有關如何安裝 PowerShell 核心的詳細資訊,請參閱在 Microsoft PowerShell 網站 PowerShell上安裝各種版本的

您可以安裝 AWSPowerShell。 NetCore 以兩種方式之一

  • 從下載模組AWSPowerShell。 NetCore.zip 並將其解壓縮到其中一個模塊目錄中。您可以顯示 PSModulePath 環境變數的值來探索自己的模組目錄。

  • 使用Install-Module指令程式從程式 PowerShell 庫安裝,如下列程序所述。

若要安裝 AWSPowerShell。 NetCore 從 PowerShell 圖庫中使用安裝模組指令程式

若要安裝 AWSPowerShell. NetCore 在 PowerShell 圖庫中,您的計算機必須運行 PowerShell 5.0 或更高版本,或者PowerShellGet在 PowerShell 3 或更高版本上運行。執行下列命令。

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 及更新版本通常 PowerShell 會在您第一次在模組中執行指令程式時,將模組載入到您的工作階段中 AWSPowerShell,. NetCore 模組太大,無法支援此功能。您必須明確載入 AWSPowerShell. NetCore 核心模塊通過運行以下命令進入您的 PowerShell 會話。

PS > Import-Module AWSPowerShell.NetCore

若要載入 AWSPowerShell. NetCore 模塊自動進入 PowerShell 會話,將該命令添加到您的 PowerShell 配置文件中。如需有關編輯設定 PowerShell 檔的詳細資訊,請參閱文件中的關於設定 PowerShell 檔

AWSPowerShell 在視窗上安裝 PowerShell

您可以使用下列 AWS Tools for Windows PowerShell 兩種方式之一來安裝:

  • AWSPowerShell.zip 下載模塊並將其解壓縮到其中一個模塊目錄中。您可以顯示 PSModulePath 環境變數的值來探索自己的模組目錄。

  • 使用Install-Module指令程式從程式 PowerShell 庫安裝,如下列程序所述。

使用安裝 PowerShell 模組指令程式 AWSPowerShell 從程式庫安裝

如果您正在運行 PowerShell 5.0 或更高版本,或者已安裝PowerShellGet在 PowerShell 3 或更高版本上,則可以 AWSPowerShell 從 PowerShell 圖庫安裝。您可以通過運行以下命令 AWSPowerShell 從微軟的PowerShell圖庫安裝和更新。

PS > Install-Module -Name AWSPowerShell

若要將 AWSPowerShell 模組自動載入 PowerShell 工作階段,請將先前的import-module指令程式新增至您的 PowerShell 設定檔。如需有關編輯設定 PowerShell 檔的詳細資訊,請參閱文件中的關於設定 PowerShell 檔

注意

默認情況下,Windows PowerShell 工具安裝在所有基於 Windows 的 Amazon 機器映像(AMI)上。

啟用指令碼執行

若要載入 AWS Tools for PowerShell 模組,您必須啟用 PowerShell 指令碼執行。欲啟用指令碼執行,請執行 Set-ExecutionPolicy cmdlet 來設定 RemoteSigned 政策。如需詳細資訊,請參閱 Microsoft Technet 網站上的 About Execution Policies

注意

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

啟用指令碼執行

  1. 需要管理員權限才能設定執行政策。如果您未以具有管理員權限的使用者身分登入,請以管理員身分開啟 PowerShell 工作階段。選擇 Start (開始),然後選擇 All Programs (所有程式)。選擇 [附件],然後選擇 [視窗] PowerShell。在 Windows 上按一下滑鼠右鍵 PowerShell,然後在內容功能表上選擇「以系統管理員

  2. 在命令提示中,輸入以下內容。

    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

Windows PowerShell 安裝程式的工具會自動更新 PS,ModulePath以包含包含AWSPowerShell模組的目錄位置。

由於PSModulePath包含 AWS 模組目錄的位置,所以Get-Module -ListAvailable指令程式會顯示該模組。

PS > Get-Module -ListAvailable ModuleType Name ExportedCommands ---------- ---- ---------------- Manifest AppLocker {} Manifest BitsTransfer {} Manifest PSDiagnostics {} Manifest TroubleshootingPack {} Manifest AWSPowerShell {Update-EBApplicationVersion, Set-DPStatus, Remove-IAMGroupPol...

版本控制

AWS AWS Tools for PowerShell 定期發行新版本,以支援新的 AWS 服務和功能。若要判斷已安裝之工具的版本,請執行 G et-AWSPowerShellVersion 指令程式。

PS > Get-AWSPowerShellVersion Tools for PowerShell Version 4.1.11.0 Copyright 2012-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. Amazon Web Services SDK for .NET Core Runtime Version 3.7.0.12 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Release notes: https://github.com/aws/aws-tools-for-powershell/blob/master/CHANGELOG.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參數新增至 G et-AWSPowerShellVersion 命令,以查看目前版本工具所支援的 AWS 服務清單。若您使用模組化的 AWS.Tools.* 選項,則只會顯示您目前已匯入的模組。

PS > Get-AWSPowerShellVersion -ListServiceVersionInfo ... Service Noun Prefix Module Name SDK Assembly Version ------- ----------- ----------- ----------- Alexa For Business ALXB AWS.Tools.AlexaForBusiness 3.7.0.11 Amplify Backend AMPB AWS.Tools.AmplifyBackend 3.7.0.11 Amazon API Gateway AG AWS.Tools.APIGateway 3.7.0.11 Amazon API Gateway Management API AGM AWS.Tools.ApiGatewayManagementApi 3.7.0.11 Amazon API Gateway V2 AG2 AWS.Tools.ApiGatewayV2 3.7.0.11 Amazon Appflow AF AWS.Tools.Appflow 3.7.1.4 Amazon Route 53 R53 AWS.Tools.Route53 3.7.0.12 Amazon Route 53 Domains R53D AWS.Tools.Route53Domains 3.7.0.11 Amazon Route 53 Resolver R53R AWS.Tools.Route53Resolver 3.7.1.5 Amazon Simple Storage Service (S3) S3 AWS.Tools.S3 3.7.0.13 ...

若要判斷您正在執行 PowerShell 的版本,請輸入$PSVersionTable以檢視 $PS VersionTable 自動變數的內容。

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

AWS Tools for PowerShell 在視窗上更新

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

更新模塊化模塊 AWS.Tools

若要將AWS.Tools模組更新為最新版本,請執行下列命令:

PS > Update-AWSToolsModule -CleanUp

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

注意

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

更新 PowerShell 核心工具

執行指Get-AWSPowerShellVersion令程式以判斷您正在執行的版本,並將其與 [PowerShell 圖庫] 網站上提供 PowerShell 的 Windows 工具版本進行比較。我們建議您每兩到三週檢查一次。只有在您更新至具有該 Support 的版本之後,才能支援新指令和 AWS 服務。

在您安裝的較新版本之前 AWSPowerShell。 NetCore,解除安裝現有的模組。在解除安裝現有套件之前,請先關閉所有開啟的 PowerShell 工作 執行下列命令以解除安裝套件。

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

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

PS > Install-Module -Name AWSPowerShell.NetCore

安裝之後,Import-Module AWSPowerShell.NetCore請執行命令,將更新的指令程式載入您的 PowerShell 工作階段。

更新視窗的工具 PowerShell

執行指Get-AWSPowerShellVersion令程式以判斷您正在執行的版本,並將其與 [PowerShell 圖庫] 網站上提供 PowerShell 的 Windows 工具版本進行比較。我們建議您每兩到三週檢查一次。只有在您更新至具有該 Support 的版本之後,才能支援新指令和 AWS 服務。

  • 若您使用 Install-Module Cmdlet 進行安裝,請執行下列命令。

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

    1. 適用於 PowerShell網站的工具下載最新版本。將所下載檔案名稱中的套件版本號碼,與您在執行 Get-AWSPowerShellVersion Cmdlet 時取得的版本號碼進行比較。

    2. 如果下載版本的數字高於您已安裝的版本,請關閉所有 Windows PowerShell 主控台工具。

    3. 安裝較新版本的視窗工具 PowerShell。

安裝之後,Import-Module AWSPowerShell請執行以將更新的指令程式載入您的 PowerShell 工作階段。或者從 [開始] 功能表執行自訂 AWS Tools for PowerShell 主控台。