AzureRmRoleAssignment拒绝访问指定的API版本

时间:2017-08-29 15:39:18

标签: powershell azure

我在运行New-AzureRmRoleAssignment时遇到错误。我想让AD组访问资源组。该脚本实际上有效 - 该组获得了对资源组的贡献者访问权限。它只是说它失败了消息“访问被拒绝指定的API版本”。

我的脚本(不包括参数)在这里:

# Import the Task.Common dll that has all the cmdlets we need for Build
import-module Microsoft.TeamFoundation.DistributedTask.Task.Common
import-module Microsoft.TeamFoundation.DistributedTask.Task.Internal
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal"
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Azure"

Write-Output "Connecting to Azure"
Initialize-AzurePowershellSupport -ConnectedServiceName $ConnectedServiceName -ErrorAction SilentlyContinue
$subscription = (Get-AzureRmContext).Subscription.SubscriptionName #(Get-AzureRmContext).Subscription.SubscriptionName

New-AzureRmRoleAssignment -ObjectId $objID -RoleDefinitionName $roleName -ResourceGroupName $environment-$featureName

如何修复错误?该脚本完成了它应该做的事情,但构建“失败”。

1 个答案:

答案 0 :(得分:1)

根据错误日志,您是否使用服务主体登录Azure。如果是,那是一个知道问题。请检查GitHub上的issue。该问题已在最新版本的Azure Power Shell(4.1.0或更高版本)上解决。

您可以使用以下cmdlet检查Azure PowerShell版本。

Get-Module -ListAvailable -Name Azure -Refresh

最新版本是4.3.1,您可以从link下载。

如果您在VSTS上构建脚本,请使用Hosted 2017 build agent,它使用最新版本的PowerShell。请参阅此answer