{"id":1894,"date":"2020-04-04T16:48:23","date_gmt":"2020-04-04T15:48:23","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1894"},"modified":"2020-04-04T16:48:29","modified_gmt":"2020-04-04T15:48:29","slug":"unregistering-an-add-in","status":"publish","type":"post","link":"https:\/\/www.stuartroberts.net\/index.php\/2020\/04\/04\/unregistering-an-add-in\/","title":{"rendered":"Unregistering an Add-in"},"content":{"rendered":"\n<p>Registering an add-in for SharePoint is easy enough. You go to the _layouts\/appregnew.aspx page for the site and register the add-in.<\/p>\n\n\n\n<p>Permissions are set when the add-in is installed on the site too. This happens after you&#8217;ve clicked Trust It when adding the add-in to a site.<\/p>\n\n\n\n<p>To revoke the permissions for an add-in in a site is also straight forward. To do this, you go to the _layouts\/appprincipals.aspx page and click the delete icon next to the add-in you want to revoke permissions for. Or for a specific web, add <em>?Scope=Web<\/em> to the URL.<\/p>\n\n\n\n<p>There&#8217;s no admin page for unregistering and add-in for a site though. To do this, we can run some PowerShell. This does require a hybrid installation where you still have access to the SharePoint farm itself and can run SharePoint PowerShell cmdlets.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The following script shows how to:<\/p>\n\n\n\n<ul><li>Revoke permissions for an add-in for a site<\/li><li>Unregister the add-in for a site<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nasnp Microsoft.SharePoint.PowerShell\n\n# Replace with the add-in's client id\n$clientId = &quot;33b85512-e4b1-529c-e012-410e676bef09&quot;\n$site = Get-SPSite &quot;url to the SP site&quot;\n$realm = Get-SPAuthenticationRealm -ServiceContext $site\n$appId = $clientId + &quot;@&quot; + $realm\n\n# Get the add-in principal for the site\n$principal = Get-SPAppPrincipal -NameIdentifier $appId -Site $site.RootWeb\n\n# Remove the permissions that were granted for this add-in in the site\nRemove-SPAppPrincipalPermission -AppPrincipal $principal -Site $site.RootWeb -Scope Site\n\n# Set the Scope parameter to SiteCollection to apply this to the site collection instead of just the web\n\n# Now to unregister the add-in\n$appManager = &#91;Microsoft.SharePoint.SPAppPrincipalManager]::GetManager($site.RootWeb)\n$appManager.DeleteAppPrincipal($principal)\n<\/pre><\/div>\n\n\n<p>To unregister we need to call the static method <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.sharepoint.spappprincipalmanager.getmanager?view=sharepoint-server\" class=\"aioseop-link\">GetManager<\/a> from the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.sharepoint.spappprincipalmanager?view=sharepoint-server\" class=\"aioseop-link\">SPAppPrincipalManager<\/a> class. There&#8217;s currently no PowerShell cmdlet that allows you to do this.<\/p>\n\n\n\n<p>You then need to call the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.sharepoint.spappprincipalmanager.deleteappprincipal?view=sharepoint-server\" class=\"aioseop-link\">DeleteAppPrincipal<\/a> method and pass it the principal object we retrieved for the add-in.<\/p>\n\n\n\n<p>Useful if you want to completely remove an add-in from a site\/site collection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Registering an add-in for SharePoint is easy enough. You go to the _layouts\/appregnew.aspx page for the site and register the add-in. Permissions are set when the add-in is installed on the site too. This happens after you&#8217;ve clicked Trust It &hellip; <a href=\"https:\/\/www.stuartroberts.net\/index.php\/2020\/04\/04\/unregistering-an-add-in\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[3],"tags":[94,93],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-uy","_links":{"self":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1894"}],"collection":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1894"}],"version-history":[{"count":2,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1894\/revisions"}],"predecessor-version":[{"id":1896,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1894\/revisions\/1896"}],"wp:attachment":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}