SharePoint online remove apps: Remove custom app using PnP PowerShell effectively

One comment

 17,535 total views,  2 views today

In this SharePoint online remove apps article, we will learn about how to remove the custom app from the SharePoint Online site using PnP PowerShell or how to remove an app from SharePoint Online using PowerShell.

SharePoint online remove apps – use case

Many times, due to technical issues we will not be able to remove the custom app installed on the SharePoint Online site manually, then we need to take the help of the PnP PowerShell command. For example, in our scenario, we were not able to remove the Nintex Forms for office 365 and Nintex Workflow for office 365. Again and again, we were getting the same error ” Sorry, we couldn’t remove the app. Click to retry”, we had tried multiple times by clicking on the “Click to retry” link but we have never been successful. Below are the error messages for the Nintex Forms for office 365 and Nintex Workflow for the office 365 app:

 

SharePoint online remove apps, sorry we couldn't remove the app - Nintex Forms for Office 365
Sorry we couldn’t remove the app – Nintex Forms for Office 365

SharePoint online remove apps, sorry we couldn't remove the app - Nintex workflow for Office 365
Sorry we couldn’t remove the app – Nintex workflow for Office 365

In the above scenario, we are bound to use the PowerShell command to remove the custom app from the SharePoint Online site.

SharePoint online remove apps –
remove app from SharePoint Online using PowerShell PnP


#The below script is used to remove the custom app installed in the SharePoint Online site.
cls

$PSshell = Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorVariable err -ErrorAction SilentlyContinue
if($PSshell -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$fileName = "Removing custom app in SPO"
#'yyyyMMddhhmm yyyyMMdd
$enddate = (Get-Date).tostring("yyyyMMddhhmmss")
#$filename = $enddate + '_VMReport.doc'
$logFileName = $fileName +"_"+ $enddate+"_Log.txt"
$invocation = (Get-Variable MyInvocation).Value
$directoryPath = Split-Path $invocation.MyCommand.Path

$directoryPathForLog=$directoryPath+"\"+"LogFiles"
if(!(Test-Path -path $directoryPathForLog))
{
New-Item -ItemType directory -Path $directoryPathForLog
#Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
#$logPath = $directoryPath + "\" + $logFileName

$logPath = $directoryPathForLog + "\" + $logFileName

$isLogFileCreated = $False

function Write-Log([string]$logMsg)
{
if(!$isLogFileCreated){
Write-Host "Creating Log File..."
if(!(Test-Path -path $directoryPath))
{
Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
else
{
$script:isLogFileCreated = $True
Write-Host "Log File ($logFileName) Created..."
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
else
{
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}

########################Remove Nintex 365 apps from SharePoint Online site##############################

#Paramaters area
$siteURL = "https://yourspositeURL"
$userName = "yourSPOUser@yourdomain.com"
$passWord = "YourSPOPassword"
#Paramaters area - Ends

$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord

Try
{
Connect-PnPOnline -Url $SiteURL -Credentials $cred

#Getting the site collection level feature by ID
#$feature = Get-PnPFeature -Scope Site -Identity $featureID
$NintexFormsforOffice365ID="255582b4-52bd-614e-9538-63ddb6b08fa5"
$NintexWorkflowforOffice365ID="dfd5a4at-4556-96de-ad0f-fa40f8c09957"

$allApps=Get-PnPAppInstance



foreach($oneApp in $allApps)
{
$appID=$oneApp.ID

#Uninstall-PnPAppInstance -Identity $NintexWorkflowforOffice365ID -force

if($oneApp.ID -eq $NintexFormsforOffice365ID)
{

#The Nintex form for offfice 365 app is being removed from the SPO site collection.
Write-host -f Yellow "Nintex form for offfice 365 app is being removed from: "$SiteURL

Uninstall-PnPApp -Identity $NintexFormsforOffice365ID -force

Write-host -f Green "The Nintex form for offfice 365 app successfully has been removed Successfully!"

}
if($oneApp.ID -eq $NintexWorkflowforOffice365ID)
{
#The Nintex workflow for offfice 365 app is being removed from the SPO site collection.
Write-host -f Yellow "The Nintex workflow for offfice 365 app is being removed from: "$SiteURL

Uninstall-PnPApp -Identity $NintexWorkflowforOffice365ID -force

Write-host -f Green "The Nintex workflow for offfice 365 app successfully has been removed Successfully!"

}

}

}
Catch
{

$ErrorMessage = $_.Exception.Message +"in remving Nintex 365 app from the SharePoint Online site!:"
Write-Host $ErrorMessage -BackgroundColor Red
Write-Log $ErrorMessage

}

########################Remove Nintex 365 apps from SharePoint Online site - Ends here ##############################

While removing the app, if we use the ‘Uninstall-PnPAppInstance’ command we will get the below warning:

“Warning – The command ‘Uninstall-PnPAppInstance’ is obsolete. use ‘Uninstall-PnPApp’ instead. ‘Uninstall-PnPAppInstance’  : No package was found for the provided app Instance.”

Remove app from SharePoint online using PowerShell, warning - The command 'Uninstall-PnPAppInstance' is obsolete - use Uninstall-PnPApp instead
Warning – The command ‘Uninstall-PnPAppInstance’ is obsolete – use Uninstall-PnPApp instead

Summary: SharePoint online remove apps using PowerShell

Thus in this tutorial, we have learned about how to remove the custom app installed on the SharePoint site using the PnP PowerShell.

See Also: SharePoint online remove apps using PowerShell

You may also like the following SharePoint PowerShell tutorials:

Hope you have enjoyed reading this article and helped you. If you would like to appreciate our efforts or if you have a better solution or a different opinion, please write to the below comment section and do share this with your friends and colleagues. 🙂


            

About Post Author

1 comments on “SharePoint online remove apps: Remove custom app using PnP PowerShell effectively”

Do you have a better solution or question on this topic? Please leave a comment