安装适用于 Azure Stack Hub 的 PowerShell AzureRM 模块Install PowerShell AzureRM module for Azure Stack Hub

Azure PowerShell AzureRM 提供了一组使用 Azure 资源管理器模型管理 Azure Stack Hub 资源的 cmdlet。Azure PowerShell AzureRM provides a set of cmdlets that use the Azure Resource Manager model for managing your Azure Stack Hub resources.

还需要使用 API 配置文件为 Azure Stack Hub 资源提供程序指定兼容的终结点。You also need to use API profiles to specify the compatible endpoints for the Azure Stack Hub resource providers.

API 配置文件提供一种管理 Azure 与 Azure Stack Hub 之间版本差异的方式。API profiles provide a way to manage version differences between Azure and Azure Stack Hub. API 版本配置文件是一组具有特定 API 版本的 Azure 资源管理器 PowerShell 模块。An API version profile is a set of Azure Resource Manager PowerShell modules with specific API versions. 每个云平台都有一组支持的 API 版本配置文件。Each cloud platform has a set of supported API version profiles. 例如,Azure Stack Hub 支持特定的配置文件版本,例如 2019-03-01-hybridFor example, Azure Stack Hub supports a specific profile version such as 2019-03-01-hybrid. 安装配置文件时,会安装与指定的配置文件对应的 Azure 资源管理器 PowerShell 模块。When you install a profile, the Azure Resource Manager PowerShell modules that correspond to the specified profile are installed.

可在已连接到 Internet、部分联网或离线场景中安装与 Azure Stack Hub 兼容的 PowerShell 模块。You can install Azure Stack Hub compatible PowerShell modules in internet-connected, partially connected, or disconnected scenarios. 本文将引导你完成适用于这些场景的详细说明。This article walks you through the detailed instructions for these scenarios.

1.验证先决条件1. Verify your prerequisites

开始使用 Azure Stack Hub 和 PowerShell AzureRM 模块之前,必须具备以下先决条件:Before you get started with Azure Stack Hub and the PowerShell AzureRM module, you must have the following prerequisites:

  • PowerShell 版本 5.1PowerShell Version 5.1
    若要检查版本,请运行 $PSVersionTable.PSVersion 并比较版本。To check your version, run $PSVersionTable.PSVersion and compare the Major version. 如果没有 PowerShell 5.1,请按照安装 Windows PowerShell 中所述进行操作。If you don't have PowerShell 5.1, follow the Installing Windows PowerShell.

    备注

    PowerShell 5.1 需要 Windows 计算机。PowerShell 5.1 requires a Windows machine.

  • 在权限提升的命令提示符下运行 PowerShell。Run PowerShell in an elevated command prompt.

  • PowerShell 库访问权限PowerShell Gallery access
    你需要有权访问 PowerShell 库You need access to the PowerShell Gallery. 该库是 PowerShell 内容的中心存储库。The gallery is the central repository for PowerShell content. PowerShellGet 模块包含用于发现、安装、更新和发布 PowerShell 项目的 cmdlet。The PowerShellGet module contains cmdlets for discovering, installing, updating, and publishing PowerShell artifacts. 这些项目的示例包括来自 PowerShell 库和其他专用存储库的模块、DSC 资源、角色功能和脚本。Examples of these artifacts are modules, DSC resources, role capabilities, and scripts from the PowerShell Gallery and other private repositories. 如果在离线场景中使用 PowerShell,则必须从已建立 Internet 连接的计算机检索资源,并将其存储在离线计算机可访问的位置。If you're using PowerShell in a disconnected scenario, you must retrieve resources from a machine with a connection to the internet and store them in a location accessible to your disconnected machine.

验证 PSGallery 是否已注册为存储库。Validate if PSGallery is registered as a repository.

备注

此步骤需要访问 Internet。This step requires internet access.

打开权限提升的 PowerShell 提示符,并运行以下 cmdlet:Open an elevated PowerShell prompt, and run the following cmdlets:

Install-module -Name PowerShellGet -Force
Import-Module -Name PackageManagement -ErrorAction Stop
Get-PSRepository -Name "PSGallery"

如果未注册存储库,请打开权限提升的 PowerShell 会话并运行以下命令:If the repository isn't registered, open an elevated PowerShell session and run the following command:

Register-PSRepository -Default
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted

3.卸载 Azure Stack Hub PowerShell 模块的现有版本3. Uninstall existing versions of the Azure Stack Hub PowerShell modules

在安装所需版本之前,请确保卸载以前安装的任何 Azure Stack Hub AzureRM PowerShell 模块。Before installing the required version, make sure that you uninstall any previously installed Azure Stack Hub AzureRM PowerShell modules. 使用以下两种方法之一卸载模块:Uninstall the modules by using one of the following two methods:

  1. 若要卸载现有的 AzureRM 和 Az PowerShell 模块,请关闭所有活动的 PowerShell 会话,并运行以下 cmdlet:To uninstall the existing AzureRM and Az PowerShell modules, close all the active PowerShell sessions, and run the following cmdlets:

    Get-Module -Name Azure* -ListAvailable | Uninstall-Module -Force -Verbose -ErrorAction Continue
    Get-Module -Name Azs.* -ListAvailable | Uninstall-Module -Force -Verbose -ErrorAction Continue
    Get-Module -Name Az.* -ListAvailable | Uninstall-Module -Force -Verbose -ErrorAction Continue
    

    如果遇到任何错误(例如“模块已在使用中”),请关闭正在使用模块的 PowerShell 会话,然后重新运行上述脚本。If you hit an error such as 'The module is already in use', close the PowerShell sessions that are using the modules and rerun the above script.

  2. C:\Program Files\WindowsPowerShell\ModulesC:\Users\{yourusername}\Documents\WindowsPowerShell\Modules 文件夹中删除以 AzureAzAzs. 开头的所有文件夹。Delete all the folders that start with Azure, Az or Azs. from the C:\Program Files\WindowsPowerShell\Modules and C:\Users\{yourusername}\Documents\WindowsPowerShell\Modules folders. 删除这些文件夹会删除任何现有的 PowerShell 模块。Deleting these folders removes any existing PowerShell modules.

4.已联网:在已建立 Internet 连接的情况下安装适用于 Azure Stack Hub 的 PowerShell4. Connected: Install PowerShell for Azure Stack Hub with internet connectivity

需要的 API 版本配置文件和 Azure Stack Hub PowerShell 模块将取决于所运行的 Azure Stack Hub 版本。The API version profile and Azure Stack Hub PowerShell modules you require will depend on the version of Azure Stack Hub you're running.

安装 Azure Stack Hub PowerShellInstall Azure Stack Hub PowerShell

运行以下 PowerShell 脚本,在开发工作站上安装这些模块:Run the following PowerShell script to install these modules on your development workstation:

对于 Azure Stack Hub 2002 或更高版本:For Azure Stack Hub 2002 or later:

可以使用 AzureRm 模块或 Az 预览版模块。You can use either user AzureRm modules or Az preview modules. 使用 Az 模块需要 Azure Stack Hub 2002 和最新修补程序。The use of the Az modules requires Azure Stack Hub 2002 and the latest hotfix.

若要使用 Az 预览版模块,请按照安装 PowerShell Az 模块中的说明进行操作。To use Az preview modules, follow the instructions at Install PowerShell Az module.

# Install the AzureRM.BootStrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRM.BootStrapper

# Install and import the API Version Profile required by Azure Stack Hub into the current PowerShell session.
Use-AzureRmProfile -Profile 2019-03-01-hybrid -Force
Install-Module -Name AzureStack -RequiredVersion 1.8.1

对于 Azure Stack Hub 1910:For Azure Stack Hub 1910:

# Install the AzureRM.BootStrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRM.BootStrapper

# Install and import the API Version Profile required by Azure Stack Hub into the current PowerShell session.
Use-AzureRmProfile -Profile 2019-03-01-hybrid -Force
Install-Module -Name AzureStack -RequiredVersion 1.8.0

备注

  • Azure Stack Hub 模块版本 1.8.0 是一个包含中断性变更的版本。Azure Stack Hub module version 1.8.0 is a breaking change release. 有关详细信息,请参阅发行说明Refer to the release note for details.

对于 Azure Stack Hub 1908 或更低版本:For Azure Stack Hub 1908 or earlier:

# Install the AzureRM.BootStrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRM.BootStrapper

# Install and import the API Version Profile required by Azure Stack Hub into the current PowerShell session.
Use-AzureRmProfile -Profile 2019-03-01-hybrid -Force
Install-Module -Name AzureStack -RequiredVersion 1.7.2

备注

Azure Stack Hub 模块版本 1.7.2 是一个包含中断性变更的版本。The Azure Stack Hub module version 1.7.2 is a breaking change release. 若要从 Azure Stack Hub 1.6.0 迁移,请参阅迁移指南To migrate from Azure Stack Hub 1.6.0, please refer to the migration guide.

确认已安装 PowerShellConfirm the installation of PowerShell

运行以下命令来确认安装:Confirm the installation by running the following command:

Get-Module -Name "Azure*" -ListAvailable
Get-Module -Name "Azs*" -ListAvailable

如果安装成功,输出中会显示 AzureRmAzureStack 模块。If the installation is successful, the AzureRm and AzureStack modules are displayed in the output.

5.离线:在未建立 Internet 连接的情况下安装 PowerShell5. Disconnected: Install PowerShell without an internet connection

在离线场景中,请先将 PowerShell 模块下载到已建立 Internet 连接的计算机。In a disconnected scenario, you first download the PowerShell modules to a machine that has internet connectivity. 然后,将它们传输到要安装的 Azure Stack 开发工具包 (ASDK)。Then, you transfer them to the Azure Stack Development Kit (ASDK) for installation.

登录到已建立 Internet 连接的计算机,并根据 Azure Stack Hub 的版本,使用以下脚本下载 Azure 资源管理器和 Azure Stack Hub 包。Sign in to a computer with internet connectivity and use the following scripts to download the Azure Resource Manager and Azure Stack Hub packages, depending on your version of Azure Stack Hub.

安装分为五步:Installation has five steps:

  1. 将 Azure Stack Hub PowerShell 安装到连接的计算机。Install Azure Stack Hub PowerShell to a connected machine.
  2. 启用其他存储功能。Enable additional storage features.
  3. 将 PowerShell 包传输到已断开连接的工作站。Transport the PowerShell packages to your disconnected workstation.
  4. 在断开连接的工作站上手动启动 NuGet 提供程序。Manually bootstrap the NuGet provider on your disconnected workstation.
  5. 确认已安装 PowerShell。Confirm the installation of PowerShell.

安装 Azure Stack Hub PowerShellInstall Azure Stack Hub PowerShell

Azure Stack Hub 2002 或更高版本。Azure Stack Hub 2002 or later.

可以使用 AzureRM 或 Az 预览版模块。You could either use AzureRM or Az preview modules. 有关 Az 模块,请参阅安装 PowerShell Az 模块中的说明。For Az modules, see instructions at Install PowerShell Az module.


Install-module -Name PowerShellGet -Force 
Import-Module -Name PackageManagement -ErrorAction Stop

$Path = "<Path that is used to save the packages>"
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureRM -Path $Path -Force -RequiredVersion 2.5.0
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureStack -Path $Path -Force -RequiredVersion 1.8.1

Azure Stack Hub 1910。Azure Stack Hub 1910.

Install-module -Name PowerShellGet -Force 
Import-Module -Name PackageManagement -ErrorAction Stop

$Path = "<Path that is used to save the packages>"
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureRM -Path $Path -Force -RequiredVersion 2.5.0
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureStack -Path $Path -Force -RequiredVersion 1.8.0

备注

Azure Stack Hub 模块版本 1.8.0 是一个包含中断性变更的版本。Azure Stack Hub module version 1.8.0 is a breaking change release. 有关详细信息,请参阅发行说明Refer to the release note for details.

对于 Azure Stack Hub 1908 或更低版本:For Azure Stack Hub 1908 or earlier:

Install-module -Name PowerShellGet -Force 
Import-Module -Name PackageManagement -ErrorAction Stop

$Path = "<Path that is used to save the packages>"
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureRM -Path $Path -Force -RequiredVersion 2.5.0
Save-Package -ProviderName NuGet -Source https://www.powershellgallery.com/api/v2 -Name AzureStack -Path $Path -Force -RequiredVersion 1.7.2

备注

Azure Stack Hub 模块版本 1.7.1 是一项中断性变更。The Azure Stack Hub module version 1.7.1 is a breaking change. 若要从 Azure Stack Hub 1.6.0 迁移,请参阅迁移指南To migrate from Azure Stack Hub 1.6.0 please refer to the migration guide.

备注

在没有 Internet 连接的计算机上,建议执行以下 cmdlet 以禁用遥测数据收集功能。On machines without an internet connection, we recommend executing the following cmdlet for disabling the telemetry data collection. 在不禁用遥测数据收集功能的情况下,可能会遇到 cmdlet 性能降级的问题。You may experience a performance degradation of the cmdlets without disabling the telemetry data collection. 这仅适用于没有 Internet 连接的计算机。This is applicable only for the machines without internet connections

Disable-AzureRmDataCollection

将包添加到工作站Add your packages to your workstation

  1. 将下载的程序包复制到 USB 设备。Copy the downloaded packages to a USB device.

  2. 登录到已断开连接的工作站,将包从 USB 设备复制到工作站中的某个位置。Sign in to the disconnected workstation and copy the packages from the USB device to a location on the workstation.

  3. 在断开连接的工作站上手动启动 NuGet 提供程序。Manually bootstrap the NuGet provider on your disconnected workstation. 有关说明,请参阅在未连接到 Internet 的计算机上手动启动 NuGet 提供程序For instructions, see Manually bootstrapping the NuGet provider on a machine that isn't connected to the internet.

  4. 将此位置注册为默认存储库,并从此存储库安装 AzureRM 和 AzureStack 模块:Register this location as the default repository and install the AzureRM and AzureStack modules from this repository:

    # requires -Version 5
    # requires -RunAsAdministrator
    # requires -Module PowerShellGet
    # requires -Module PackageManagement
    
    $SourceLocation = "<Location on the development kit that contains the PowerShell packages>"
    $RepoName = "MyNuGetSource"
    
    Register-PSRepository -Name $RepoName -SourceLocation $SourceLocation -InstallationPolicy Trusted
    
    Install-Module -Name AzureRM -Repository $RepoName
    
    Install-Module -Name AzureStack -Repository $RepoName
    

确认已安装 PowerShellConfirm the installation of PowerShell

运行以下命令来确认安装:Confirm the installation by running the following command:

Get-Module -Name "Azure*" -ListAvailable
Get-Module -Name "Azs*" -ListAvailable

6.配置 PowerShell 以使用代理服务器6. Configure PowerShell to use a proxy server

在需要代理服务器访问 Internet 的场景中,请先将 PowerShell 配置为使用现有的代理服务器:In scenarios that require a proxy server to access the internet, you first configure PowerShell to use an existing proxy server:

  1. 打开提升的 PowerShell 命令提示符。Open an elevated PowerShell prompt.

  2. 运行以下命令:Run the following commands:

    #To use Windows credentials for proxy authentication
    [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
    
    #Alternatively, to prompt for separate credentials that can be used for #proxy authentication
    [System.Net.WebRequest]::DefaultWebProxy.Credentials = Get-Credential
    

已知问题Known issue

get_SerializationSettings 方法错误Method get_SerializationSettings error

  • 原因:PowerShell Az 模块与 PowerShell AzureRM 模块不兼容。Cause: The PowerShell Az module and PowerShell AzureRM modules are not compatible.

    以下错误指示 AzureRM 模块和 Az 模块在同一会话中加载:The following error indicates that the AzureRM modules and Az modules are loaded in the same session:

    >  Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does 
    not have an implementation.
    
  • 补救措施:卸载冲突的模块。Remediation: Uninstall the conflicting modules.

    若要使用 AzureRM 模块,请卸载 Az 模块。If you would like to use the AzureRM modules, uninstall the Az modules. 或者,若要使用 Az 模块,请卸载 AzureRM 模块。Or uninstall the AzureRM if you would like to use the Az modules. 关闭 PowerShell 会话并卸载 Az 或 AzureRM 模块。Close your PowerShell session and uninstall either the Az or AzureRM modules.

    可以在卸载 Azure Stack Hub PowerShell 模块的现有版本中找到相关说明。You can find instructions at Uninstall existing versions of the Azure Stack Hub PowerShell modules.

后续步骤Next steps