使用 Azure PowerShell 进行身份验证

本页介绍如何使用 Azure PowerShell 通过用户帐户或 Microsoft Entra ID 服务主体登录到 Azure Databricks。

以用户身份登录

若要使用 用户帐户登录,请运行 Connect-AzAccount cmdlet,并按照屏幕上的说明作:

Connect-AzAccount

注释

如果 PowerShell 无法识别 Connect-AzAccount,请通过运行 Install-Module -Name Az -Repository PSGallery -Force来安装它。

请通过运行以下命令来验证您的订阅:

Get-AzContext | Select-Object -ExpandProperty Subscription

若要获取正确的订阅 ID,请执行以下作:

  • Azure 门户: 单击用户名 >Azure 门户>概述。 复制 订阅 ID
  • 帐户控制台: 单击用户名 >“管理帐户>工作区”,搜索工作区,并记下 “订阅 ”字段。

根据需要切换订阅:

Set-AzContext -Name "<subscription-name>"
# Or
Set-AzContext -Subscription <subscription-id>

如果看到 The subscription of '<subscription-id>' doesn't exist in cloud 'AzureCloud',请通过运行 curl -v <per-workspace-URL>/aad/auth来获取租户 ID。 在 location 响应标头中查找 ID。 请参阅 “获取订阅和租户 ID”。 然后重新连接:

Connect-AzAccount -Tenant <tenant-id> | Format-Table

以 Microsoft Entra ID 服务主体身份登录

重要

Databricks 建议对大多数用例使用 Azure Databricks 托管服务主体 。 仅在需要访问 Azure 资源时才使用 Microsoft Entra ID 托管服务主体,因为这需要额外的 Microsoft Entra ID 权限。

若要使用 Microsoft Entra ID 服务主体登录,请从 Microsoft Entra ID 应用程序收集以下内容:

  • 租户 ID: 目录(租户)ID
  • 客户端 ID: 应用程序(客户端)ID
  • 客户端密码: 机密值

通过一次运行以下命令登录:

$SecurePassword = ConvertTo-SecureString -String "<Client-secret>" -AsPlainText -Force
$TenantId = "<Tenant-ID>"
$ApplicationId = "<Client-ID>"
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationId, $SecurePassword
Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential

注释

如果 PowerShell 无法识别 Connect-AzAccount,请通过运行 Install-Module -Name Az -Repository PSGallery -Force来安装它。

按照 用户登录中的步骤验证订阅并根据需要切换。