SharePoint Online: Remove custom app using PnP PowerShell

No comments

 844 total views,  4 views today

In this article, we will learn about how to remove the custom app from the SharePoint Online site using PnP PowerShell. 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:

 

Sorry we couldn't remove the app - Nintex Forms for Office 365
Sorry we couldn’t remove the app – Nintex Forms for Office 365

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.

Remove the custom app from SharePoint Online site using PnP PowerShell


#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.”

Warning - The command 'Uninstall-PnPAppInstance' is obsolete - use Uninstall-PnPApp instead
Warning – The command ‘Uninstall-PnPAppInstance’ is obsolete – use Uninstall-PnPApp instead

Summary:

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

See Also:

You may also like the following SharePoint PowerShell tutorials:

Free download SharePoint Online & Office 365 Administration eBook(238 Pages)

Get the PDF eBook from here:


 
FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.