Sometime O365 SharePoint Online will not allow uninstall app hosted. It will give you error as “Some things went wrong” or “Unable to Uninstall” and gives you message something like e-Discovery or retention polity contact Administrator.

Such case if you try to deploy app using Visual Studio then you will get error:

here 2 errors will display

Script to Uninstall:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Function Get-ClientContext([string]$Url,[string]$UserName,[string]$Password)
{
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context
}

Function Uninstall-AppInstance([Microsoft.SharePoint.Client.ClientContext]$Context,[Guid]$AppInstanceId)
{
    $appInst = $Context.Web.GetAppInstanceById($AppInstanceId)
    $appInst.Uninstall()
    $context.ExecuteQuery()
 }

$UserName = "rijwan@sharepoint.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://rijwan.sharepoint.com/"
$AppInstanceid = New-Object Guid("XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")  #specify App Instance Id here

$context = Get-ClientContext -Url $Url -UserName $UserName -Password $Password
Uninstall-AppInstance -Context $context -AppInstanceId $AppInstanceid
$context.Dispose()

How to get App Instance Id:

Click on App setting (…)AppID.png

Click Details of App

Check the URL: (Ex: https://rijwan.sharepoint.com/sites/appdev/_layouts/15/AppMonitoringDetails.aspx?AppInstanceId=ccf0108c-f95c-489f-91fe-b1345a7f27de)

App Instance ID: ccf0108c-f95c-489f-91fe-b1345a7f27de

This way we can get App Instance ID and using above PS script let us delete app.

 

 

By Rijwan Ansari

Research and Technology Lead | Software Architect | Full Stack .NET Expert | Tech Blogger | Community Speaker | Trainer | YouTuber. Follow me @ https://rijsat.com Md Rijwan Ansari is a high performing and technology consultant with 10 plus years of Software Development and Business Applications implementation using .NET Technologies, SharePoint, Power Platform, Data, AI, Azure and cognitive services. He is also a Microsoft Certified Trainer, C# Corner MVP, Microsoft Certified Data Analyst Associate, Microsoft Certified Azure Data Scientist Associate, CSM, CSPO, MCTS, MCP, with 15+ Microsoft Certifications. He is a research and technology lead in Tech One Global as well as leading Facebook community Cloud Experts Group and SharePoint User Group Nepal. He is a active contributor and speaker in c-sharpcorner.com community, C# Corner MVP and his rank at 20 among 3+ millions members. Additionally, he is knee to learn new technologies, write articles, love to contribute to the open-source community. Visit his blog RIJSAT.COM for extensive articles, courses, news, videos and issues resolution specially for developer and data engineer.

Leave a Reply

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