Az Powershell throwing exception in DevOps release pipeline
There is an exception thrown while executing New-AzAdServicePrincipal in Azure release pipeline, while same command ran from local machine succeeds without any issues...
$Password = "somepasswordhere"
Import-Module -Name Az.Resources # Imports the PSADPasswordCredential object
$credentials = New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential -Property @{StartDate=Get-Date; EndDate=Get-Date -Year 2124; Password=$Password}
$sp = New-AzAdServicePrincipal -DisplayName 'principalName' -PasswordCredential $credentials
Error in Azure release pipeline: 2020-07-29T14:03:54.0700833Z ##[error]Resource not found for the segment 'me'. 2020-07-29T14:03:54.1932824Z ##[error]PowerShell exited with code '1'.
@matendie , In DevOps, I believe you connect Azure using service principle. Could you try the same service principle in your local code?
@dingmeng-xue Yes, it does run using a service principal, I thought about it, but the exception doesn't say anything about permissions. I will see if I can get its password reset and use it to run it from local machine.
OK, I logged in to Azure using my service principal and got the same error as in release pipeline. So I guess there is something wrong with the Principal? What is wrong though? How can I tell what needs to be fixed?
My personal account, which works, has only one role "Application administrator | Assignments" So does this Service Principal that I'm using for release "Application administrator | Assignments"
There is no known to me difference between them.
New-AzAdServicePrincipal : Resource not found for the segment 'me'. At line:14 char:7
- $sp = New-AzAdServicePrincipal -DisplayName "$RealmMgrWebName$Identit ...
- CategoryInfo : InvalidArgument: (:) [New-AzADServicePrincipal], Exception
- FullyQualifiedErrorId : Microsoft.Azure.Commands.ActiveDirectory.NewAzureADServicePrincipalCommand
My understanding is you need to go to your SP on Portal. Then, go to API permission, add application permission around Azure Active Directory Graph (such as Application.ReadWrite.OwnedBy), grant permission. If you still meet problem, please contact Azure support. We have limited knowledge on this area.
dingmeng-xue Thank you for that info, I will try it!
Close this issue now. Please contact us if you have further question.