I have written a module to create an app registration in Azure AD and assign roles and scopes. When using my own credentials as a Global Administrator to connect to Azure AD it works but when using a Service Principal with certificate thumbprint it returns the following
PS C:\WINDOWS\system32> New-AzureADServiceAppRoleAssignment -ObjectId "GUID" -PrincipalId "GUID"
-ResourceId "GUID" -Id "GUID"
New-AzureADServiceAppRoleAssignment : Error occurred while executing NewServicePrincipalAppRoleAssignment
Code: Request_BadRequest
Message: One or more properties are invalid.
RequestId: 8ab86d25-3963-4d67-a112-44285bc74c82
DateTimeStamp: Tue, 17 Dec 2019 13:04:10 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:1 char:1
+ New-AzureADServiceAppRoleAssignment -ObjectId "GUID...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureADServiceAppRoleAssignment], ApiException
+ FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.NewServicePrincipalAppRoleAssignment
at <ScriptBlock>, <No file>: line 1