29 January 2016

Get-SPAppPrincipal/Register-SPAppPrincipal giving error

Today, I was running few PowerShell commands to configure server to server authentication for Federated Search.

I was following this URL - https://technet.microsoft.com/en-us/library/dn197169.aspx

While running following commands, I was getting error

Register-SPAppPrincipal -site $site.rootweb -nameIdentifier $sponameidentifier -displayName "SharePoint Online"

OR

Get-SPAppPrincipal -site $site.rootweb -nameIdentifier $sponameidentifier

Error was -

Get-SPAppPrincipal : We're sorry, we weren't able to complete the operation, please try again in a few minutes. If you
see this message repeatedly, contact your administrator.
At line:1 char:1

+ Get-SPAppPrincipal -site $site.rootweb -nameIdentifier $sponameidentifier
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...GetAppPrincipal:SPCmdletGetAppPrincipal) [Get-SPAppPrinc
   ipal], SPException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetAppPrincipal


I was not facing this problem when running same commands in a different SharePoint server.

Finally after lot of research and digging through ULS logs, I found the solution for that. I had created App Management Service Proxy earlier in the day on this new SharePoint server. When we create App Manager Service Proxy, it creates its own database which generally starts with name 'App_Managament_<GUID>'.

This database name can be found by going to Central Admin --> Backup & Restore --> Shared Services --> App Management Service Application.

My login id did not had permissions on this database. Once permission was granted, I was able to query this database via PowerShell commands and both my commands started working fine.

No comments: