Using AzureADPreview (2.0.1.18) for Powershell i am trying to add a policy to an application:
Add-AzureADApplicationPolicy -Id dc1b1cbf-356a-4d0a-a3b2-e7a0e3125aa2 -RefObjectId 36e8328a-17b5-4d64-a12f-dfac959c3b8b
But i get:
Add-AzureADApplicationPolicy : Error occurred while executing AddApplicationPolicy
Code: Request_ResourceNotFound
Message: Resource 'dc1b1cbf-356a-4d0a-a3b2-e7a0e3125aa2' does not exist or one of its queried reference-property objects are not present.
InnerError:
RequestId: 0663394a-b556-4bb6-a3c1-96a8fac3e5ec
DateTimeStamp: Wed, 12 Sep 2018 09:04:58 GMT
HttpStatusCode: NotFound
HttpStatusDescription: Not Found
HttpResponseStatus: Completed
At line:1 char:1
+ Add-AzureADApplicationPolicy -Id dc1b1cbf-356a-4d0a-a3b2-e7a0e3125aa2 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-AzureADApplicationPolicy], ApiException
+ FullyQualifiedErrorId : Microsoft.Open.MSGraphBeta.Client.ApiException,Microsoft.Open.MSGraphBeta.PowerShell.AddApplicationPolicy
So it seems like it cannot find the application. However i am able to find the application like this:
Get-AzureADApplication -Filter "AppId eq 'dc1b1cbf-356a-4d0a-a3b2-e7a0e3125aa2'"
ObjectId AppId DisplayName
-------- ----- -----------
9125a684-e262-4215-8e35-5d3d628d27f2 dc1b1cbf-356a-4d0a-a3b2-e7a0e3125aa2 MyAppname
I have been able to do this previously on the same tenant with the same policy. So something has happened which is causing this. I have tried on other applications for the tenant, but get the same error.
Currently, it is not available. In the official doc, it says
The Add-AzureADApplicationPolicy cmdlet is not available at this time .
Update(10/23/2019):
Looks it can be used by the object id of the application now.
Add-AzureADApplicationPolicy -Id <object id of application> -RefObjectId <object id of policy>