通过服务主体进行自动化

服务主体是在租户中创建的 Microsoft Entra 应用程序资源,用于执行无人值守的资源和服务级操作。 它们是具有应用程序 ID 和密码或证书的唯一 用户标识 类型。 服务主体仅具有执行由为其分配的角色和权限定义的任务所需的权限。

在 Analysis Services 中,服务主体与 Azure 自动化、PowerShell 无人参与模式、自定义客户端应用程序和 Web 应用一起使用,以自动执行常见任务。 例如,可以使用服务主体自动预配服务器、部署模型、数据刷新、纵向扩展/缩减和暂停/恢复。 通过角色成员身份为服务主体分配权限,这与常规Microsoft Entra UPN 帐户类似。

Analysis Services 不支持由服务主体托管标识执行的操作。 要了解详细信息,请参阅 Azure 资源的托管标识支持 Microsoft Entra 身份验证的 Azure 服务

创建服务主体

可以在 Azure 门户中或使用 PowerShell 创建服务主体。 若要了解详细信息,请参阅:

创建服务主体 - Azure 门户
创建服务主体 - PowerShell

在 Azure 自动化中存储凭据和证书资产

服务主体凭据和证书可以安全地存储在 Azure 自动化中,以便执行 Runbook 操作。 若要了解详细信息,请参阅:

Azure 自动化中的凭据资产
Azure 自动化中的证书资产

将服务主体添加到服务器管理员角色

必须先将服务主体添加到服务器管理员角色,然后才能将其用于 Analysis Services 服务器管理操作。 必须直接将服务主体添加到服务器管理员角色。 不支持先将服务主体添加到安全组,然后再将该安全组添加到服务器管理员角色。 若要了解详细信息,请参阅 向服务器管理员角色添加服务主体

连接字符串中的服务主体

服务主体 appID 和密码或证书可用于连接字符串中,这与 UPN 大致相同。

PowerShell

注释

建议使用 Azure Az PowerShell 模块与 Azure 交互。 若要开始,请参阅安装 Azure PowerShell。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

使用 Az.AnalysisServices 模块

Az.AnalysisServices 模块中使用服务主体执行资源管理作时,请使用 Connect-AzAccount cmdlet。

在以下示例中,appID 和密码用于执行控制平面操作,以同步到只读副本并进行扩展:

Param (
        [Parameter(Mandatory=$true)] [String] $AppId,
        [Parameter(Mandatory=$true)] [String] $PlainPWord,
        [Parameter(Mandatory=$true)] [String] $TenantId
       )
$PWord = ConvertTo-SecureString -String $PlainPWord -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $AppId, $PWord

# Connect using Az module
Connect-AzAccount -Credential $Credential -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx"

# Synchronize a database for query scale out
Sync-AzAnalysisServicesInstance -Instance "asazure://westus.asazure.windows.net/testsvr" -Database "testdb"

# Scale up the server to an S1, set 2 read-only replicas, and remove the primary from the query pool. The new replicas will hydrate from the synchronized data.
Set-AzAnalysisServicesServer -Name "testsvr" -ResourceGroupName "testRG" -Sku "S1" -ReadonlyReplicaCount 2 -DefaultConnectionMode Readonly

使用 SQLServer 模块

在以下示例中,appID 和密码用于执行模型数据库刷新作:

Param (
        [Parameter(Mandatory=$true)] [String] $AppId,
        [Parameter(Mandatory=$true)] [String] $PlainPWord,
        [Parameter(Mandatory=$true)] [String] $TenantId
       )
$PWord = ConvertTo-SecureString -String $PlainPWord -AsPlainText -Force

$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $AppId, $PWord

Invoke-ProcessTable -Server "asazure://westcentralus.asazure.windows.net/myserver" -TableName "MyTable" -Database "MyDb" -RefreshType "Full" -ServicePrincipal -ApplicationId $AppId -TenantId $TenantId -Credential $Credential

AMO 和 ADOMD

使用客户端应用程序和 Web 应用进行连接时,来自 NuGet 的 AMO 和 ADOMD 客户端库 版本 15.0.2 及更高版本的可安装包使用以下语法支持连接字符串中的服务主体: app:AppID 和密码或 cert:thumbprint

在以下示例中,appIDpassword 被用来执行模型数据库刷新操作:

string appId = "xxx";
string authKey = "yyy";
string connString = $"Provider=MSOLAP;Data Source=asazure://westus.asazure.windows.net/<servername>;User ID=app:{appId};Password={authKey};";
Server server = new Server();
server.Connect(connString);
Database db = server.Databases.FindByName("adventureworks");
Table tbl = db.Model.Tables.Find("DimDate");
tbl.RequestRefresh(RefreshType.Full);
db.Model.SaveChanges();

后续步骤

使用 Azure PowerShell 登录
使用逻辑应用刷新
使用 Azure 自动化进行刷新
将服务主体添加到服务器管理员角色
使用服务主体自动执行 Power BI Premium 工作区和数据集任务