<# .SYNOPSIS Script to register new sites with the Gimmal Records SharePointOnline Connector (SPOC). This script assumes that the updated v6.x SPOC has been deployed and configured correctly. -- 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 will read a CSV file of site URLs and attempt to register each with the SPOC. .NOTES 1) Update the Configuration Variables section in the code below. 2) Script sould be run from a server/workstation that has the required PowerShell module installed. 3) This 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 ------------------------------------------------------------- If site is already registered in SPOC, the request is considered to have succeeded (i.e. no error returned, line is skipped) .CMD LINE n/a .COMPONENT Requires PowerShell v5.1 / v7.5.4+ Requires PnP PowerShell (v3.1.0 PnP.PowerShell or higher) #> # # ================================ # Update these Configuration variables # ================================ # $sitesToUpdate = ".\sitesToUpdate.csv" # The name and path of the CSV file that contains the list of sites to register $username = "" # Name of a SPOC Administrator Account to use $password = "" # Password for the SPOC Administrator Account listed above $baseUrl = "" # This is the URL that you use to access the SPOC Administrator Web Portal (e.g. https://spo-records.gimmal.cloud or https://spo-records-ca.gimmal.cloud) # DO NOT ALTER ANY VALUES BELOW THIS LINE # ================================ # Build needed URLs - # ================================ # $endpoint = "/api/v1/sites" $url = "$baseUrl$endpoint" # # ================================ # Build Basic Auth header # ================================ # $pair = "$username`:$password" $bytes = [System.Text.Encoding]::UTF8.GetBytes($pair) $base64Creds = [Convert]::ToBase64String($bytes) $headers = @{ Authorization = "Basic $base64Creds" "Content-Type" = "application/json" "Accept" = "application/json" } #Maintain site counts $successCount = 0 $notFoundCount = 0 $errorCount = 0 #Load the CSV site list $siteCount = 0 Import-Csv -Path $sitesToUpdate | ForEach-Object { $siteCount++ # ================================ # JSON body # ================================ # $bodyObject = @{ siteUrl = $($_.SiteUrl) isActive = $true startJob = $false } $bodyJson = $bodyObject | ConvertTo-Json -Depth 3 # ================================ # POST request # ================================ try { $response = Invoke-RestMethod ` -Method Post ` -Uri $url ` -Headers $headers ` -Body $bodyJson $successCount++ Write-Host "Request succeeded" -foregroundcolor DarkYellow Write-Host "Site Registered: " $response.data.siteUrl -foregroundcolor DarkYellow } catch { Write-Host "ERROR: Request failed:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red if ($_.Exception.Response -ne $null) { $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream()) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $responseBody = $reader.ReadToEnd() $json = $responseBody | ConvertFrom-Json Write-Host "Error Detail: " $json.error.detail -foregroundcolor Red } $errorCount++ } } # Summary Write-Host "`n========== SUMMARY ==========" -ForegroundColor Cyan Write-Host "Total sites processed: $siteCount" -ForegroundColor White Write-Host "Total Sites Registered: $successCount sites" -ForegroundColor Green Write-Host "Errors encountered: $errorCount sites" -ForegroundColor Red Write-Host "==============================" -ForegroundColor Cyan