<# .SYNOPSIS Script to remove the legacy SharePoint Online Connector (SPOC) App (called 'SharePoint Online Connector') on listd (existing) sites and replace it with the new v6.x SPOC App (called 'Gimmal Records SharePoint Online Connector'). If neiher is deployed to the listed site the new App is added. Assumes that the updated v6.x SPOC App has been deployed to the SharePoint App Catalog. Assumes user running the script has Administrator-level access to all sites being updated. Script uses Interactive login. -- v1.0 - 02/18/2026 - RTW -- initial version NOTE: THis script is provided without any explicitly or implicitly granted warranties or guarantees. It has been successfully used internally by Gimmal/Morae Client Services, but should not be considered production-ready off-the-shelf software. Clients are responsible for their own verification and testing in/by client's own DEV/TEST environment BEFORE using against a PROD environment. .DESCRIPTION This script looks to see if the legacy SPOC App is installed and then removes it. It then adds the new v6.x SPOC App to the site collection. .NOTES Assumes that an Enterprise App/App Registration is available for application-based PowerShell Authentication/Automation which has sufficient access to the sites being updated (Sites.FullControl.All is recommmended) This script should be run from a server/workstation that has the required PowerShell module installed. The script uses a CSV input file with the list of sites to update. We recommand placing the CSV into the runtime directory where the script is located and running script from there. THe format of the CSV is: ------------------------------------------------------------- SiteUrl https://tenant.sharepoint.com/sites/someSiteName1 https://tenant.sharepoint.com/sites/someSiteName2 ------------------------------------------------------------- .CMD LINE n/a .COMPONENT Requires PowerShell v7.5.4+ Requires PnP PowerShell (v3.1.0 PnP.PowerShell or higher) #> <# UNCOMMENT THIS SECTION AND POPULATE THE VALUES TO RUN USING CMD LINE param ( [Parameter(Mandatory = $true)][string]$appId = "*******", [Parameter(Mandatory = $false)][string]$tenantId = "*******", [Parameter(Mandatory = $false)][string]$certThumbprint = "*******", [Parameter(Mandatory = $false)][string]$sitesToUpdate = "sitesToUpdate.csv" ) #> # # ================================ # Update these Configuration variables # ================================ # $appId = "********-****-****-****-************" #ID of the App Reg set up for PowerShell script execution (NOT the ID of the SPOC App Registration) $sitesToUpdate = ".\sitesToUpdate.csv" #Name of the CSV file that provides the site list # DO NOT ALTER ANY VALUES BELOW THIS LINE # ================================ # App Name Defaults # ================================ # #Default Legacy and Current SPOC App Names $oldAddinName = "SharePoint Online Connector" $newAddInName = "Gimmal Records SharePoint Online Connector" #Maintain site counts $successCount = 0 $notFoundCount = 0 $errorCount = 0 #Load the CSV site list $siteCount = 0 Import-Csv -Path $sitesToUpdate | ForEach-Object { $siteCount++ #Remove existing SPOC Addin try { Write-Host "Checking site: $($_.SiteUrl)" -ForegroundColor Cyan # Connect to site using App Registration $ctxSp = Connect-PnPOnline -url $($_.SiteUrl) -Interactive -ClientId $appId # Get all apps/add-ins on the site $apps = Get-PnPApp -Connection $ctxSp # Find your add-in $yourAddin = $apps | Where-Object { $_.Title -eq $oldAddinName } if ($yourAddin) { Write-Host "`tFound add-in - Removing..." -ForegroundColor Yellow # Remove the Legacy App Uninstall-PnPApp -Identity $yourAddin.Id -Connection $ctxSp Write-Host "`tSuccessfully removed app from: $($_.SiteUrl)" -ForegroundColor Yellow $successCount++ } else { Write-Host "`tLegacy App not found on this site: $($_.SiteUrl)" -ForegroundColor DarkYellow $notFoundCount++ } } catch { Write-Host "`tERROR on $($_.SiteUrl): $_" -ForegroundColor Red $errorCount++ } #NOw add new SPOC Addin #Verify App exists -- if not, install it write-host ("`tChecking for " + $newAddInName + " on site ... ") -ForegroundColor Yellow try{ $appIsInstalled = $false $web = Get-PnPWeb -Includes AppTiles -Connection $ctxSp $appTiles = $web.AppTiles Invoke-PnPQuery -Connection $ctxSp foreach ($appTile in $appTiles) { if (($appTile.appType -eq "Instance") -and ($appTile.Title -eq $newAddInName)) { $appIsInstalled = $true } } If ($appIsInstalled -eq $false){ #Get the App from App Catalog write-host ("`tInstalling " + $newAddInNamee + " to site ... ") -ForegroundColor Yellow $App = Get-PnPApp -Scope Tenant -Connection $ctxSp | Where {$_.Title -eq $newAddInName} #Install App to the Site Get-PnPApp -Identity $App.Id -Connection $ctxSp | Install-PnPApp -Connection $ctxSp Write-Host "`tSuccessfully added new App to: $($_.SiteUrl)" -ForegroundColor Yellow }else{ write-host ("`t" + $newAddInName + " already installed ... ") -ForegroundColor DarkYellow } }catch{ Write-Host "`tERROR on $($_.SiteUrl): $_" -ForegroundColor Red } } # Summary Write-Host "`n========== SUMMARY ==========" -ForegroundColor Cyan Write-Host "Total sites checked: $siteCount" -ForegroundColor White Write-Host "Legacy Add-in replaced on: $successCount sites" -ForegroundColor Green Write-Host "Legacy Add-in not found on: $notFoundCount sites" -ForegroundColor Gray Write-Host "Errors encountered: $errorCount sites" -ForegroundColor Red Write-Host "==============================" -ForegroundColor Cyan