Find SharePoint Online sites with certain name – PNP PowerShell script
This PNP PowerShell script we used scan all SPO sites and find sites that has NotesA in the site name.
Below script uses Azure enterprise app authentication method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
cls Function LogWrite { Param ([string]$logstring) Add-content -Encoding UTF8 $Logfile -value $logString } filter timestamp {"$(Get-Date -Format G): $_"} $logfile = "c:\temp\NotesA_SP_Site_Export.csv" $logExists = (Test-Path $logfile) if ($logExists) {clear-content $logfile} LogWrite $logStr $clientId = "cb899782-6b0c-41b2-8c43-f7d7733c7845" $spBase = "https://lialis.sharepoint.com" $tenantid = "tenatid goes here" $pfxpath = "C:\EAppsCerts\Pipe001.pfx" $certpassword = "cert password goes here" $pnpConnect = Connect-PnPOnline -Url $spBase -ClientId $clientId -CertificatePath $pfxpath -CertificatePassword (ConvertTo-SecureString -AsPlainText $certpassword -Force) -Tenant $tenantid -WarningAction Ignore $context = Get-PnPContext $web = $context.Web $context.load($web) $tenantSites = Get-PnPTenantSite -Filter "Url -like 'NotesA-'" $spsitecount = 1 foreach($tenantSite in $tenantSites) { $siteLists = Get-PnPList | Where-Object {$_.Hidden -eq $false} foreach($list in $siteLists){ $tenantListTitle = $list.Title } $tenantSiteTitle = $tenantSite.Title $tenantSiteURL = $tenantSite.Url #marten had to connect to the site at this point in the script, else it would work on the lialis.sharepoint.com instead of the sub site $pnpConnect = Connect-PnPOnline -Url $tenantSiteURL -ClientId $clientId -CertificatePath $pfxpath -CertificatePassword (ConvertTo-SecureString -AsPlainText $certpassword -Force) -Tenant $tenantid -WarningAction Ignore #Write-host "Index found=$aspxindexpagecount Views found=$aspxviewcount Notes docs found=$aspxnotescontent - $tenantSiteURL - $NotesMigrartionLibrary" Write-host "$tenantSiteURL" $logStr = "`$"+"SiteURL$spsitecount = ""$tenantSiteURL""" $spsitecount++ LogWrite $logStr } |