Scenario
Sometimes we add third party apps from Sharepoint Store to SPO app catalog site. However, these apps are not available for the users on SPO sites' Apps You Can Add section. The app was not properly installed because of the presence of stale entry; so we removed the app instances from app catalog and then added the apps again to appcatalog and now the apps are available for all SPO sites through addanapp.aspx page without navigating to SharePoint store.
1) To remove the app instance from app catalog, the account should have admin permission for app catalog site.
2) Now, we need to specify app Instance ID.
PowerShell script
- [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 = "User ID"
- $Password = Read - Host - AsSecureString "Enter the password"
- $Url = "https://chrfr.sharepoint.com/sites/appcatalog"
- $AppInstanceid = New - Object Guid("8d457aa3-89f6-45df-bf6a-b1845c00d3e9")# specify App Instance Id here
- $creds = New - Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password)
- $context = New - Object Microsoft.SharePoint.Client.ClientContext($Url)
- $context.credentials = $creds
- Uninstall - AppInstance - Context $context - AppInstanceId $AppInstanceid
- $context.Dispose()
Conclusion
In this blog, I provided a PowerShell script to remove the app instance from app catalog.