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()
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