SharePoint Online: Uninstall App Instance using PowerShell

Requirement: Uninstall an App Instance using PowerShell.

PowerShell to Remove an App instance from SharePoint Online Site

Could not remove an app instance in the SharePoint Online site from the browser interface! Here is the PowerShell to remove an app from the SharePoint Online site.

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Legal"
$AppInstanceID = New-Object Guid("d0c3efd3-4ac4-4172-a3ed-aa108845aced")
 
#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)
    $Ctx.Load($App)
    $Ctx.ExecuteQuery()

    #Uninstall App Instance
    $App.Uninstall()
    $Ctx.ExecuteQuery()
    
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

How to get App Instance Id?

To obtain the App instance ID, follow these steps:

  • Go to your SharePoint Online site where the App instance is created
  • Click on Settings gear >> Site Contents
  • In the Site contents page, Hover over the app and click on ellipses(…) of the App and click the Details menu
  • The app instance ID can be obtained from the details URL. E.g. Url: /_layouts/15/AppMonitoringDetails.aspx?AppInstanceId={GUID}

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply