使用PowerShell在Azure中以服务主体ID登录时无法获取订阅详细信息

问题描述 投票:0回答:1

我正在尝试使用PowerShell以服务主体ID登录。通过这样做,我想与我的Azure Data Factory连接并停止触发器。但是在执行代码的初始阶段,它会给出一个错误。我粘贴了一段代码和结果。

$resourceGroupName = 'my-resource-group'
$dataFactoryName = 'my-azure-data-factory-name'
$applicationid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
$secretKey = 'my-secret-key'
$tenantID = 'my-tenant-id'

$password = ConvertTo-SecureString -String $secretKey -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($applicationid,$password)
$x= Login-AzureRmAccount -ServicePrincipal -Credential $cred -Tenant $tenantID

#Gather a list of triggers to stop them
$allTriggers = Get-AzureRmDataFactoryV2Trigger -ResourceGroupName $resourceGroupName -DataFactoryName $dataFactoryName

结果:

enter image description hereenter image description here

powershell azure-active-directory subscription azure-powershell service-principal
1个回答
0
投票

嗯,我可以重现您的问题,这是由您的服务负责人在您的数据工厂/订阅中没有作用引起的。

enter image description here

[要解决此问题,请在门户中导航至ADF或订阅-> Access control (IAM)->将您的服务主体添加为角色,例如,Data Factory Contributor/ Contributor。要添加角色,登录门户网站的用户帐户必须是ADF /订阅的Owner角色。

enter image description here

添加角色后,运行命令再次登录,即可正常工作。 (我使用新的Az模块进行测试,对于您的Az模块,这是相同的逻辑)

AzureRm

© www.soinside.com 2019 - 2024. All rights reserved.