您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

新 Azure Powershell Az 模块简介Introducing the new Azure PowerShell Az module

从 2018 年 12 月起,Azure PowerShell Az 模块将正式发布,它现在是用于与 Azure 进行交互的首选 PowerShell 模块。Starting in December 2018, the Azure PowerShell Az module is in general release and now the intended PowerShell module for interacting with Azure. Az 提供了更短的命令,提高了稳定性,并提供了跨平台支持。Az offers shorter commands, improved stability, and cross-platform support. Az 还提供与 AzureRM 的功能奇偶一致性以及轻松从 AzureRM 执行迁移的途径。Az also offers feature parity and an easy migration path from AzureRM.

有了 Az 模块,Azure PowerShell 现在就可以在 Windows 上兼容 PowerShell 5.1,以及在所有支持的平台(包括 Windows、macOS 和 Linux)上兼容 PowerShell Core 6.x 及更高版本。With the Az module, Azure PowerShell is now compatible with PowerShell 5.1 on Windows and PowerShell Core 6.x and later on all supported platforms - including Windows, macOS, and Linux.

Az 是一个新模块,因此,版本已重设为 1.0.0。Az is a new module, so the version has been reset to 1.0.0.

为何使用新模块?Why a new module?

主要更新可能会带来不方便,因此我们必须让你知道,为何我们决定引入一组包含新 cmdlet 的新模块,以便通过 PowerShell 与 Azure 交互。Major updates can be inconvenient, so it's important that we let you know why the decision was made to introduce a new set of modules, with new cmdlets, for interacting with Azure from PowerShell.

最大和最重要的变化是,在引入基于 .NET Standard 库的 PowerShell Core 6.x 后,PowerShell 就成为了一个跨平台的产品。The biggest and most important change is that PowerShell has been a cross-platform product since the introduction of PowerShell Core 6.x, based on the .NET Standard library. 我们致力于为所有平台提供 Azure 支持,这意味着需要更新 Azure PowerShell 模块,使之能够使用 .NET Standard 并与 PowerShell Core 兼容。We're committed to bringing Azure support to all platforms, which means that the Azure PowerShell modules needed to be updated to use .NET Standard and be compatible with PowerShell Core. 为了添加此支持,我们创建了 Az 模块,而不是使用现有的 AzureRM 模块并引入复杂的变化。Rather than taking the existing AzureRM module and introduce complex changes to add this support, the Az module was created.

创建新模块也为我们的工程师提供了使 cmdlet 和模块的设计和命名保持一致的机会。Creating a new module also gave our engineers the opportunity to make the design and naming of cmdlets and modules consistent. 所有模块现在都以 Az. 前缀开头,cmdlet 都使用“谓词 -Az 名词”形式。All modules now start with the Az. prefix and cmdlets all use the Verb-AzNoun form. 以前,cmdlet 名称不仅长,而且不一致。Previously, cmdlet names were not only longer, there were inconsistencies in cmdlet names.

模块数目也减少了:某些与相同的服务配合使用的模块已集中在一起,管理平面和数据平面 cmdlet 现在都包含在其服务的单一模块中。The number of modules was also reduced: Some modules which worked with the same services have been rolled together, and management plane and data plane cmdlets are now contained all within single modules for their services. 这可以大大方便那些手动管理依赖项和导入内容的用户。For those of you who manually manage dependencies and imports, this makes things much simpler.

我们的团队始终致力于简化 Azure 与 PowerShell cmdlet 的配合使用方式,使之与以前相比能够在尽可能多的平台上使用,因此进行了这些需要构建新 Azure PowerShell 模块的重要更改。By making these important changes that required building a new Azure PowerShell module, the team has committed to making it easier than ever, and on more platforms than previously possible, to use Azure with PowerShell cmdlets.

升级到 AzUpgrade to Az

为了使用 PowerShell 中的最新 Azure 功能,应尽快迁移到 Az 模块。To keep up with the latest Azure features in PowerShell, you should migrate to the Az module as soon as possible. 如果尚未做好安装 Az 模块来替换 AzureRM 的准备,可以通过多个可用的选项来试验 Az:If you're not ready to install the Az module as a replacement for AzureRM, you have a couple of options available to experiment with Az:

  • PowerShell 环境与 Azure Cloud Shell 配合使用。Use a PowerShell environment with Azure Cloud Shell. Azure Cloud Shell 是一个基于浏览器的 shell 环境,该环境安装了 Az 模块并启用了 Enable-AzureRM 兼容性别名。Azure Cloud Shell is a browser-based shell environment which comes with the Az module installed and Enable-AzureRM compatibility aliases enabled.
  • 始终将 AzureRM 模块与 Windows 版 PowerShell 5.1 安装在一起,而对于 PowerShell Core 6.x 或更高版本,则安装 Az 模块。Keep the AzureRM module installed with PowerShell 5.1 for Windows, but install the Az module for PowerShell Core 6.x or later. Windows 版 PowerShell 5.1 和 PowerShell Core 使用不同的模块集合。PowerShell 5.1 for Windows and PowerShell Core use separate collections of modules. 按说明安装 PowerShell Core,然后从 PowerShell Core 终端安装 Az 模块Follow the instructions to install PowerShell Core and then install the Az module from a PowerShell Core terminal.

若要从现有的 AzureRM 安装升级,请执行以下操作:To upgrade from an existing AzureRM install:

  1. 卸载 Azure PowerShell AzureRM 模块Uninstall the Azure PowerShell AzureRM module
  2. 安装 Azure PowerShell Az 模块Install the Azure PowerShell Az module
  3. 可选:熟悉新的命令集后,通过 Enable-AzureRMAlias 启用兼容模式为 AzureRM cmdlet 添加别名。OPTIONAL: Enable compatibility mode to add aliases for AzureRM cmdlets with Enable-AzureRMAlias while you become familiar with the new command set. 有关更多详细信息,请参阅下一部分或开始从 AzureRM 迁移到 AzSee the next section or Start migration from AzureRM to Az for more details.

将现有脚本迁移到 AzMigrate existing scripts to Az

新 cmdlet 名称已设计为易于学习。The new cmdlet names have been designed to be easy to learn. 请在 cmdlet 名称中使用 Az,而不是使用 AzureRmAzureInstead of using AzureRm or Azure in cmdlet names, use Az. 例如,旧命令 New-AzureRMVm 已变为 New-AzVmFor example, the old command New-AzureRMVm has become New-AzVm. 但是,在进行迁移时,不能仅仅熟悉新的 cmdlet 名称就可以了:还必须了解重命名的模块、参数以及其他重要更改。Migration is more than just becoming familiar with the new cmdlet names, though: There are renamed modules, parameters, and other important changes.

我们提供了一些资源,帮助你了解从 AzureRM 迁移到 Az 的过程:To help you with the process of migration from AzureRM to Az, we've got a number of resources:

Az 模块提供了一个兼容模式,方便你在更新到新语法期间使用现有脚本。The Az module has a compatibility mode to help you use existing scripts while you update to the new syntax. Enable-AzureRmAlias cmdlet 可通过别名启用兼容模式,让你能够在完全迁移到 Az 的过程中使用现有的脚本,几乎不需要对其进行修改。The Enable-AzureRmAlias cmdlet enables a compatibility mode through aliases, to allow you to use existing scripts with minimal modification while working towards a full migration to Az.

重要

对于 Az cmdlet 来说,即使 cmdlet 名称使用了别名,也仍然可能存在新的(或重命名的)参数或更改的返回值。Even though the cmdlet names are aliased, there may still be new (or renamed) parameters or changed return values for the Az cmdlets. 不要期望让别名为你处理迁移事项!Don't expect enabling aliases to take care of the migration for you! 请参阅中断性变更完整列表,了解在什么情况下可能需要对脚本进行更新。See the full breaking changes list to find where your scripts may require updates.

对 AzureRM 的持续支持Continued support for AzureRM

现有 AzureRM 模块将不会再收到新的 cmdlet 或功能。The existing AzureRM module will no longer receive new cmdlets or features. 不过,至少在 2020 年 12 月之前,我们仍会对 AzureRM 进行官方维护和 Bug 修复。However, AzureRM is still officially maintained and will get bug fixes up through at least December 2020.

如果你对 Az 模块是否功能完备、是否经过测试或者是否已做好生产准备存有疑虑,请注意:所有曾经在 AzureRM 中开展的工程工作目前都集中在 Az 上,包括尽可能提高现有模块的代码重用率,以及通过广泛的测试确保新模块在功能方面兼容。If you have concerns about whether or not the Az module is as fully-featured, tested, or production ready: All of the engineering work that went into AzureRM has now been focused on Az, including as much code reuse of the existing modules as was possible, and extensive testing to make the new modules feature-compatible. 是否迁移到 Az 应该单纯取决于组织的计划,不需等待特定功能的发布。Moving onto Az should be influenced by your organization's schedule alone, without needing to wait on specific features to appear.