Remove App from SharePoint Online with Powershell

Hi,

Today I was facing some issues in installed custom app. I was not able to get App Details & also not able to remove the app. I tried alot from interface but I couldn't remove the app. Then I move to Powershell scripts.

Here is the powershell script which can remove the app from SharePoint Online. Only prerequisite is you must have SharePoint Online Client Components SDK installed on the system.

cls
[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 = "gaurav.goyal@myorgs.com"
$Password=Read-Host -Prompt "Password" -AsSecureString;

$Url = "https://mytenant.sharepoint.com"
$AppInstanceid = New-Object Guid("XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")  #you need to specify App Instance Id here

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

Uninstall-AppInstance -Context $context -AppInstanceId $AppInstanceid
$context.Dispose()

Comments

Popular Posts

SharePoint Interview Questions and Answers

Download Infopath Form Templates

How to get current logged user information using JavaScript ?

Steps to set Form based authentication (FBA) for SharePoint 2010

SharePoint Interview Questions and Answers II

Get List Items - JavaScript

Change Language for current user with JSOM in SharePoint Online

Cross Site List Rollup Web Part for SharePoint 2010

Hide Recently Modified Items

SharePoint 2010 CSS Chart