Reputation: 1867
I am trying to login in with service principal id using PowerShell. By doing this I want to connect with my Azure Data Factory and stop triggers. But at the initial phase of execution of code it gives an error. I paste a piece of code and results.
$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
Result:
Upvotes: 0
Views: 1048
Reputation: 42143
Well, I can reproduce your issue, this was caused by your service principal who did not have a role in your data factory/subscription.
To fix the issue, navigate to the ADF or subscription in the portal -> Access control (IAM)
-> add your service principal as a role, e.g. Data Factory Contributor
/ Contributor
. To add the role, your user account which logged in the portal needs to be the Owner
role of your ADF/subscription.
After adding the role, run the command to login again, then it will work fine. (I test with the new Az
module, for your AzureRm
module, it is the same logic)
Upvotes: 1