2

I need the powershell script to uninstall the sharepoint app from office 365 site. I tried below script did not work for me.

    $getinstances = Get-SPAppInstance -Web https://spnote.sharepoint.com
    $getapp = $getinstances  | where {$_.Title -eq 'ArchiveDocs.app'} 
    Uninstall-SPAppInstance -Identity $getapp
4

Get-SPAppInstance cmdlet along with another cmdlets are supported in SharePoint On-Premises only, they are not supported in Office 365.

The following script demonstrates how uninstall App in SharePoint Online:

Prerequisites: SharePoint Online Client Components SDK

[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 = "jdoe@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.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

  1. Go to Site Settings
  2. Click a ... link for an App and click Details menu item (see picture below)
  3. Once the detail page will be opened, App Instance Id could be grabbed from Url: /_layouts/15/AppMonitoringDetails.aspx?AppInstanceId=<AppInstanceId>

enter image description here

  • 1
    Thanks Vadim. This is working for me. Only change that i made in my code is to get the app using product id as i am unable to find the appinstace id. I will appreciate if you can let me know how i can see the appinstance id of my custom App. – Surya May 19 '15 at 7:40
  • Sure, see the updated answer :) – Vadim Gremyachev May 19 '15 at 8:02
2

The above method to get the App Instance ID only works if the app is installed, & you are able to get to its details page. I ran into an issue where the app was partially removed & when trying to reinstall I saw this message

"You can't add this app here."

I couldn't go to the App Details page, as described in Vadim's answer, to get the App Instance ID.

So, I got the App Instance Id from this page instead https://my-tenant.sharepoint.com/_api/web/AppTiles

  1. Goto above link & Save the XML
  2. Open the xml in IE(or other xml reader) and search for your App's title
  3. Under the <entry> tag, look for a GUID in the <d:AppId> tag. This is the App Instance ID you are looking for.

Run Vadim's script above, with the app instance id, to remove the app in the limbo state. After I did this, the "You can't add this app here." message was cleared & I could reinstall the app.

Hope this helps someone out. I wanted to post this as a comment to Vadim's answer, but stackexchange rules won't allow me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.