我正在尝试使用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
结果:
嗯,我可以重现您的问题,这是由您的服务负责人在您的数据工厂/订阅中没有作用引起的。
[要解决此问题,请在门户中导航至ADF或订阅-> Access control (IAM)
->将您的服务主体添加为角色,例如,Data Factory Contributor
/ Contributor
。要添加角色,登录门户网站的用户帐户必须是ADF /订阅的Owner
角色。
添加角色后,运行命令再次登录,即可正常工作。 (我使用新的Az
模块进行测试,对于您的Az
模块,这是相同的逻辑)
AzureRm