2

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.

  • In the [official doc](https://learn.microsoft.com/en-us/powershell/module/azuread/add-azureadapplicationpolicy?view=azureadps-2.0-preview), it says `The Add-AzureADApplicationPolicy cmdlet is not available at this time .` May be the error was caused by it? – Joy Wang Sep 12 '18 at 09:34
  • I think you might be right about that. – Thomas Therkildsen Sep 12 '18 at 09:37
  • 1
    I encountered the same problem using both the AppID and the ObjectID from the Azure Portal. The ObjectId returned by the `Get-AzureADApplication` cmdlet was different from that in the portal, and worked. – wonderb0lt Oct 23 '19 at 07:55

2 Answers2

2

You need to provide application's object Id instead of applicationId

in your case, object id is 9125a684-e262-4215-8e35-5d3d628d27f2

So the command would be

Add-AzureADApplicationPolicy -Id 9125a684-e262-4215-8e35-5d3d628d27f2 -RefObjectId 36e8328a-17b5-4d64-a12f-dfac959c3b8b
whatsinaname
  • 186
  • 9
1

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>
Joy Wang
  • 39,905
  • 3
  • 30
  • 54