在 azure devops 中使用 azure powershell 内联任务将 azuresqlserveractivedirecoty admin 设置为 azure sqlsever 中的 ADgroup

set azuresqlserveractivedirecoty admin to ADgroup in azure sqlsever using azure powershell inline task in azure devops

我正在尝试在 azure devops 中执行以下命令以将 AD 组设置为 setsqlserveradmin。

Set-AzSqlServerActiveDirectoryAdministrator -ResourceGroupName "xyz" -ServerName "xyzsqlserver" -DisplayName "ADgroup" -ObjectId "27f75d8c-xxxx-xxxx-xxxx-xxxxxxxxxx" 

下面是错误日志

2020-05-07T15:55:05.2211587Z ##[command]Disconnect-AzAccount -Scope Process 
    ErrorAction Stop 2020-05-07T15:55:05.6167436Z ##[command]Clear-AzContext -Scope Process - ErrorAction 
    Stop 2020-05-07T15:55:05.9479005Z ##[error]Cannot find the Azure Active Directory object 'Adgroup'. 
    Please make sure that the user or group you are authorizing is registered in the current 
    subscription's Azure Active directory. To get a list of Azure Active Directory groups use Get- 
    AzADGroup, or to get a list of Azure Active Directory users use Get-AzADUser. 2020-05- 
    07T15:55:06.0117846Z ##[section]Finishing: Azure PowerShell script: InlineScript

注意 - 我检查了 Adgroup 并且相应的 objectid 是正确的。

powershell 任务 4.0 和版本 3.1.0

我可以重现你的问题,首先,确保该组在你的服务连接的同一个租户中。

然后导航到 Azure 门户 -> Azure Active Directory -> App registrations -> 找到与您的服务连接相关的 AD App 注册,按照以下步骤添加 Azure Active Directory Graph(不是Microsoft Graph)的申请权限 Directory.Read.All,别忘了点击Grant admin consent for xxx按钮终于。

添加权限后,有一些延迟(30m - 1h),然后测试命令,可以。