Remove App Instances from a SharePoint site using PowerShell

Have you ever come across a problem with uninstalling an APP from SharePoint Online or is the APP stuck during uninstallation with an error “Sorry something went wrong with adding the app. click to retry”? If yes, you are at the right place and I have a solution for you.

Recently when trying to uninstall apps from the SharePoint Online site collection, I came across the problem below –

I waited for a couple of hours and the APP was not removed. At this point, I decided to use PowerShell and try my luck.

Trying to use PNP SharePoint Online Module :

Like any SharePoint Administrator, I tried to first get all the apps (Get-PnPApp) from my SharePoint Online Site Collection by then I realized the command did not return me the full list of Apps. On searching the internet, I found that this is a problem highlighted in PnP-PowerShell and is still open as of 16th August 2022. So its time for Plan B.

Resolving the problem using the Client Side Object Model :

After having no luck with the PNP commadlets, I decided to try my luck with SharePoint CSOM(client-side object model) and it worked.

To run the script we need the App Instance Id? How to get App Instance Id?

  • Navigate to your SharePoint Online site where the App is installed
  • Click on Site Settings and Site Contents.
  • Click on ellipses(…) of the App and click the Permission menu.
  • In the URL you should see the App Instance Id.

The Script –

#Set Parameters
$SiteURL = ""
$AppInstanceID = New-Object Guid("<your-app- guid>")
#Setup Credentials to connect
$Cred = Get-Credential
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    #Get the App
    $App = $Ctx.Web.GetAppInstanceById($AppInstanceID)

    #Uninstall App Instance
Catch {
    write-host -f Red "Error:" $_.Exception.Message

All Done!  Launch PowerShell ISE as an administrator and run the script, after a few seconds the APP will be removed from your SharePoint Online site collection.

Subscribe to this blog for the latest updates about SharePoint Online, Nintex, Microsoft Flow, Power Apps, and document conversion and manipulation.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s