Friday 17 March 2017

Uninstalling app in SharePoint Online

This post will guide you on how to uninstall app in SharePoint Online.
For installing any app you can install it from SharePoint APP Store.

So lets get started :)

We have one and only pre-requisite for this that you must have SharePoint Online Client Components SDK installed on the system.

Now we have to get the APP instance ID. Follow below steps to get the ID.

1. Go to the site collection where app is installed
2. Go to Site setting and click a link for an App > Click Details menu item.
3. Now from URL we can get the instance ID

https://sharepoint.com/_layouts/15/appstore.aspx?AppInstanceId=<AppInstanceId>

 Use below script to uninstall the App in SharePoint Online.


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

Function Get-ClientContext([string]$Url,[string]$UserName,[string]$Password)

{   $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)

   $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password)
   return $context

}

Function Uninstall-AppInstance([Microsoft.SharePoint.Client.ClientContext]$Context,[Guid]$AppInstanceId)

{   $appInst = $Context.Web.GetAppInstanceById($AppInstanceId)

   $appInst.Uninstall()

   $context.ExecuteQuery()

 }

$UserName = "rahul.dagar@sharepoint.com"

$Password=Read-Host -Prompt "Password" -AsSecureString;

$Url = "https://App.sharepoint.com"

$AppInstanceid = New-Object Guid("APP INSTANCE ID")

$context = Get-ClientContext -Url $Url -UserName $UserName -Password $Password

Uninstall-AppInstance -Context $context -AppInstanceId $AppInstanceid

$context.Dispose()

Also you can check below script
https://gallery.technet.microsoft.com/office/Uninstall-unwanted-app-f18b39c0 

Hope it helps:)

Happy SharePointing :)

No comments:

Post a Comment