Forum Discussion

coxygt's avatar
coxygt
Brass Contributor
May 17, 2024

How to see where Connectors are used in SharePoint online

Morning,

So have just read MC793656 in the Message Centre of my companies tenant advising the retirement of 365 connects from SharePoint Online (SPO) webparts, but I cannot find any method on how to check if any of the sites on my companies tenant are using this, anyone know how this can be checked as I have over 9,000 sites on the tenant?

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    coxygt 

    To identify where Connectors are used in SharePoint Online (SPO) webparts across a large number of sites in your tenant, you can use a combination of PowerShell scripts and SharePoint Online APIs. Here’s a step-by-step approach to help you achieve this:

    Step 1: Prerequisites

    1. Install the SharePoint Online Management Shell: Make sure you have the SharePoint Online Management Shell installed. You can download it from here.
    2. Install the PnP PowerShell Module: PnP PowerShell provides additional cmdlets that can simplify the process of interacting with SharePoint Online.
    Install-Module -Name PnP.PowerShell

    Step 2: Connect to SharePoint Online

    Use the following command to connect to your SharePoint Online tenant:

    Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Interactive

    Replace yourtenant with your actual tenant name.

    Step 3: Retrieve All Site Collections

    Fetch all site collections in your tenant:

    $siteCollections = Get-SPOSite -Limit All

    Step 4: Check for Connectors in Webparts

    You will need to iterate through each site collection, then each web part on each page within those sites to check for Connectors.

    Here's a script to help you get started. Note that this is a simplified version and may need to be adjusted for your specific environment and requirements.

    Powershell code is untested, please backup first.

    # Load SharePoint Online PnP module
    Import-Module PnP.PowerShell
    
    # Connect to SharePoint Online
    Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Interactive
    
    # Get all site collections
    $siteCollections = Get-SPOSite -Limit All
    
    # Create a list to store results
    $connectorUsage = @()
    
    foreach ($site in $siteCollections) {
        Write-Host "Processing site: $($site.Url)"
        Connect-PnPOnline -Url $site.Url -Interactive
    
        # Get all webs in the site collection
        $webs = Get-PnPSubWeb -Recurse
        $webs += Get-PnPWeb
    
        foreach ($web in $webs) {
            Write-Host "Processing web: $($web.Url)"
            Connect-PnPOnline -Url $web.Url -Interactive
    
            # Get all pages in the web
            $pages = Get-PnPListItem -List "Site Pages"
    
            foreach ($page in $pages) {
                $pageUrl = "$($web.Url)/SitePages/$($page.FieldValues["FileLeafRef"])"
                Write-Host "Processing page: $pageUrl"
    
                # Load the page contents
                $pageContents = Get-PnPClientSidePage -Identity $page.FieldValues["FileLeafRef"]
    
                # Check for connectors in web parts
                foreach ($control in $pageContents.Controls) {
                    if ($control.ControlType -eq 3 -and $control.JsonWebPartData -like "*Connectors*") {
                        $connectorUsage += [PSCustomObject]@{
                            SiteUrl = $site.Url
                            WebUrl = $web.Url
                            PageUrl = $pageUrl
                            WebPartTitle = $control.Title
                        }
                    }
                }
            }
        }
    }
    
    # Output the results
    $connectorUsage | Export-Csv -Path "ConnectorUsage.csv" -NoTypeInformation

    Explanation

    1. Connect to SharePoint Online: Establish a connection to your SharePoint Online tenant.
    2. Retrieve Site Collections: Get all site collections in your tenant.
    3. Iterate Through Sites and Webs: For each site collection, retrieve all subsites (webs).
    4. Retrieve Pages: Get all pages within each web.
    5. Check Webparts: Inspect each web part on each page to check for the presence of Connectors.
    6. Store Results: Store any findings in a list and export the results to a CSV file.

    Important Considerations

    • Permissions: Ensure the account used to run the script has the necessary permissions to access all sites and their contents.
    • Performance: Running this script for a large number of sites (like 9,000) can be time-consuming. Consider running it during off-peak hours.
    • Error Handling: Enhance the script with error handling to manage and log any access issues or failures.

    Final Steps

    After running the script, review the ConnectorUsage.csv file to identify which sites and pages are using Connectors. This file will provide a detailed list of locations where Connectors are found, allowing you to take appropriate action before their retirement.

    Note: My knowledge of this topic is limited, but since no one has answered it, I entered your question in various AI. The text, steps and the code was created with the help of AI.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you, if it doesn't help you, please just ignore it.

     

    Was the answer useful? Mark as best response and like it!

    This will help all forum participants.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

     

    Was the answer useful? Mark as best response and like it!

    This will help all forum participants.

Resources