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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *