Microsoft Azure PowerShell
此仓库包含供开发人员和管理员开发、部署、管理和维护 Microsoft Azure 资源的 PowerShell cmdlet。
Az PowerShell 模块已预装在 Azure Cloud Shell 中。
模块
下表列出了 Azure PowerShell 汇总模块。
| 描述 | 模块名称 | PowerShell Gallery 链接 |
|---|---|---|
| Azure PowerShell | Az | |
| 包含预览模块的 Azure PowerShell | AzPreview |
有关此仓库中模块的完整列表,请参阅 Azure PowerShell 模块。
安装
PowerShell Gallery
在 PowerShell 会话中运行以下命令以安装 Az PowerShell 模块:
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
PowerShell 7 的最新版本 是在所有平台(包括 Windows、Linux 和 macOS)上与 Az PowerShell 模块配合使用的推荐 PowerShell 版本。该模块 也可在 Windows PowerShell 5.1 上运行,需搭配 .NET Framework 4.7.2 或更高版本。
Az 模块取代了 AzureRM。不应将 Az 与 AzureRM 并排安装。
如果你已从 PowerShell 库安装了较早版本的 Azure PowerShell 模块,并希望更新到最新版本,请在 PowerShell 会话中运行以下命令:
Update-Module -Name Az -Scope CurrentUser -Force
Update-Module 将新版本与之前的版本并行安装。它不会卸载
之前的版本。
有关安装 Azure PowerShell 的更多信息,请参阅 安装指南。
用法
登录 Azure
要连接到 Azure,请使用 Connect-AzAccount cmdlet:
# Opens a new browser window to log into your Azure account.
Connect-AzAccount
# Log in with a previously created service principal. Use the application ID as the username, and the secret as password.
$Credential = Get-Credential
Connect-AzAccount -ServicePrincipal -Credential $Credential -TenantId $TenantId
要登录到特定的云(AzureChinaCloud、AzureCloud、AzureUSGovernment),请使用
Environment 参数:
# Log into a specific cloud, for example the Azure China cloud.
Connect-AzAccount -Environment AzureChinaCloud
会话上下文
会话上下文在 Azure PowerShell 模块和 PowerShell 实例之间持久化登录信息。使用 Get-AzContext cmdlet 查看当前会话中使用的上下文。结果包含 Azure 租户和订阅。
# Get the Azure PowerShell context for the current PowerShell session
Get-AzContext
# Lists all available Azure PowerShell contexts in the current PowerShell session
Get-AzContext -ListAvailable
要获取租户中的订阅,请使用 Get-AzSubscription cmdlet:
# Get all of the Azure subscriptions in your current Azure tenant
Get-AzSubscription
# Get all of the Azure subscriptions in a specific Azure tenant
Get-AzSubscription -TenantId $TenantId
若要更改当前上下文所使用的订阅,请使用
Set-AzContext cmdlet:
# Set the Azure PowerShell context to a specific Azure subscription
Set-AzContext -Subscription $SubscriptionName -Name 'MyContext'
# Set the Azure PowerShell context using piping
Get-AzSubscription -SubscriptionName $SubscriptionName | Set-AzContext -Name 'MyContext'
有关 Azure PowerShell 上下文的详细信息,请参阅 Azure PowerShell 上下文对象。
发现 cmdlet
使用 Get-Command 来发现特定模块内的 cmdlet,或符合特定搜索模式的 cmdlet:
# List all cmdlets in the Az.Accounts module
Get-Command -Module Az.Accounts
# List all cmdlets that contain VirtualNetwork in their name
Get-Command -Name '*VirtualNetwork*'
# List all cmdlets that contain VM in their name in the Az.Compute module
Get-Command -Module Az.Compute -Name '*VM*'
Cmdlet 帮助和示例
若要查看 cmdlet 的帮助内容,请使用 Get-Help cmdlet:
# View basic help information for Get-AzSubscription
Get-Help -Name Get-AzSubscription
# View the examples for Get-AzSubscription
Get-Help -Name Get-AzSubscription -Examples
# View the full help for Get-AzSubscription
Get-Help -Name Get-AzSubscription -Full
# View the online version of the help from https://learn.microsoft.com for Get-AzSubscription
Get-Help -Name Get-AzSubscription -Online
有关使用 Azure PowerShell 的详细说明,请参阅入门指南。
报告问题和反馈
问题
如果你在使用 Azure PowerShell 时发现任何 bug,请在我们的 GitHub 仓库 中提交问题。 使用适当的信息填写问题模板。
或者,如果你在使用 Azure PowerShell 或 Azure 服务时遇到问题,请参阅 Azure 社区支持。
反馈
如果你希望在 Azure PowerShell 中看到某个功能,请使用
Send-Feedback cmdlet,或在我们的 GitHub 仓库 中提交问题。
贡献
有关为此仓库做出贡献的详细信息,请参阅贡献指南和Azure PowerShell 开发者指南。
本项目欢迎贡献和建议。大多数贡献要求你同意贡献者许可协议 (CLA),声明你有权并且确实授予我们使用你贡献的权利。有关详细信息,请访问 https://cla.microsoft.com。
当你提交拉取请求时,CLA-bot 将自动确定你是否需要提供 CLA,并相应地标记 PR(例如,标签、评论)。只需按照机器人提供的说明操作即可。你只需要在所有使用我们 CLA 的仓库中执行一次此操作。
本项目已采纳 Microsoft 开源行为准则。有关更多信息,请参阅 行为准则常见问题解答 或联系 opencode@microsoft.com 提出任何额外的问题或意见。
遥测
Azure PowerShell 默认会收集遥测数据。Microsoft 会聚合收集的数据以识别
使用模式,从而识别常见问题并改进 Azure PowerShell 的体验。
Microsoft Azure PowerShell 不会收集任何私有或个人数据。例如,使用
数据有助于识别诸如 cmdlet 成功率低等问题,并帮助我们确定工作优先级。虽然我们
感谢这些数据提供的见解,但我们理解并非所有人都希望发送使用
数据。您可以使用
Disable-AzDataCollection cmdlet 禁用数据收集。要了解更多信息,请参阅我们的
隐私声明。
了解更多
本项目已采纳 Microsoft 开源行为准则。有关 更多信息,请参阅 行为准则常见问题解答 或联系 opencode@microsoft.com 提出任何额外的问题或意见。