Skip to main content

Identifying Stream Web Parts in SharePoint Pages

Microsoft recently announced that they are discontinuing the classic Stream and introducing a new version. This change necessitates the identification of Stream web parts across SharePoint pages within your organization. To help with this transition, you can use a PowerShell script to scan your SharePoint sites for any Stream web parts that may be in use. Below is a detailed explanation of how to achieve this using PowerShell and the PnP PowerShell module.

Script Overview

The script provided here connects to your SharePoint Online sites, iterates through all site pages, and checks for the presence of Stream web parts. It compiles a list of these pages and exports the information to a CSV file.

Key Components of the Script

1. Parameters and Global Collection Initialization

$PagesDataCollGlobal = @()

2. Function Definition: CheckWebParts

This function connects to a given site, retrieves all site pages, and checks each page for Stream web parts.

Function CheckWebParts(){
    Param
    (
        $siteURL = $(throw "Please Enter Value:"),
        $siteTitle=$(throw "Please Enter Value:")
    )
    Connect-PnPOnline -Url $siteURL -interactive
    $PagesDataColl = @()
    $SitePages = Get-PnPListItem -List "Site Pages"
    ForEach($Page in $SitePages)
    {
        $webpartFound = "No"
        write-host $Page.FieldValues.FileLeafRef -ForegroundColor Green
        $page= Get-PnPClientSidePage -Identity $Page.FieldValues.FileLeafRef
        $webParts = $page.Controls 
        foreach($webpart in $webparts) {    
            If($webpart.Title -Contains "Stream")
            {
                $webpartFound = "Yes"
            }
        }  
        $Data = New-Object PSObject -Property ([Ordered] @{
            PageName  = $Page.PageTitle
            RelativeURL = $siteURL + "/SitePages/" + $Page.Name   
            FileName = $Page.Name
            SiteURL = $siteURL
            SiteName = $siteTitle
            HasStream = ($webpartFound -eq "Yes"?"Yes": "No")
        })
        $PagesDataColl += $Data
        If($webpartFound -eq "Yes"){ write-host "stream found" -ForegroundColor Yellow}
    }
    return $PagesDataColl
}

3. Main Script Logic

The script connects to the root site, retrieves all subsites, and calls the CheckWebParts function for each site and its subsites recursively.

$SiteURL = "YOUR SITE URL"
$CSVFile = "C:\Temp\SitePages.csv"
Connect-PnPOnline -Url $SiteURL -interactive
$sites = Get-PnPSubWeb
$PagesDataColl = @()
foreach ($site in $sites)
{
    $PagesDataCollGlobal += CheckWebParts -siteURL $site.URL -siteTitle $site.Title 
    Connect-PnPOnline -Url $site.Url -interactive
    $subsites = Get-PnPSubWeb 
    foreach ($siteTemp in $subsites)
    {
        $PagesDataCollGlobal += CheckWebParts -siteURL $siteTemp.URL -siteTitle $siteTemp.Title 
        Connect-PnPOnline -Url $siteTemp.Url -interactive
        $subsites1 = Get-PnPSubWeb 
        foreach ($siteTemp1 in $subsites1){
            $PagesDataCollGlobal += CheckWebParts -siteURL $siteTemp1.URL -siteTitle $siteTemp1.Title 
            Connect-PnPOnline -Url $siteTemp1.Url -interactive
            $subsites2 = Get-PnPSubWeb 
            foreach ($siteTemp3 in $subsites2){
                $PagesDataCollGlobal += CheckWebParts -siteURL $siteTemp3.URL -siteTitle $siteTemp3.Title 
                Connect-PnPOnline -Url $siteTemp3.Url -interactive
                $subsites3 = Get-PnPSubWeb 
                foreach ($siteTemp4 in $subsites3){
                    $PagesDataCollGlobal += CheckWebParts -siteURL $siteTemp4.URL -siteTitle $siteTemp4.Title 
                }
            }
        }
    }
}
$PagesDataCollGlobal

# Export data to CSV File
$PagesDataCollGlobal | Export-Csv -Path $CSVFile -NoTypeInformation

Running the Script

1. Install the PnP PowerShell Module

If you haven't already, install the PnP PowerShell module:

Install-Module -Name PnP.PowerShell

2. Connect to Your SharePoint Online Site

Update the $SiteURL variable with your SharePoint site URL.

3. Execute the Script

Run the script in a PowerShell window. Ensure you have the necessary permissions to access the SharePoint sites.

4. Review the Output

The script will generate a CSV file at the specified path ($CSVFile), listing all pages with and without Stream web parts.

Conclusion

This script provides a systematic approach to identify Stream web parts across your SharePoint pages, helping you prepare for the transition to the new Stream. By exporting the results to a CSV file, you can easily review and manage the impacted pages.

Regards,
Keyur Pandya

Connect with me on LinkedIn

Comments

Popular posts from this blog

Identity client runtime library (IDCRL) did not get a response from the login server.

Recently I was doing some testing with a background PowerShell and encountered a weird error. “Identity client runtime library (IDCRL) did not get a response from the login server”. The error that you might encounter while working with PowerShell. This error is very misleading when it comes to identifying what could go wrong. After doing quite a good amount of research below are the probable causes for the error. Invalid Credentials MFA (Multi-Factor Authentication) Manage security defaults. Solutions Invalid Credentials Check if your credentials are wrong. Especially if you are using variables. MFA (Multi-Factor Authentication) Check if MFA is enabled on the account which you are using. These only affect you badly if you are developing PowerShell for a background Job. Go to Microsoft 365 admin center Users -> Active users -> Select the user -> Manage multifactor authentication -> Select the user -> Disable multi-factor authentication. M

Business Data Connectivity

I came to a requirement wherein I was supposed to get data from an 3 rd party portal using API’s and then bring them to SharePoint server. The first approach that I finalized was just to make BDC solution that will get data from 3 rd party portal and will deploy it to SharePoint. How to Create BDC solution in SharePoint? I found below link that is having really great description about hot to create and deploy the BDC solution to SharePoint. http://www.c-sharpcorner.com/uploadfile/hung123/creating-business-data-connectivity-service-using-visual-studio-2010/ After creating an POC I came to know that BDC model cannot be deployed on Multi tenant farm. So what can be done next? After some amount of googling I came to know that we can create BDC solution using WCF services also. So I created a WCF service solution that acted as a wrapper that used to fetch data from the portal. We can them publish that service to IIS or Server and use the service referen

New-PnPTenantSite: The remote server returned an error: (401) Unauthorized.

New-PnPTenantSite: The remote server returned an error: (401) Unauthorized. Recently I was working on automate SharePoint site provisioning PnP script. We wanted to schedule this script to auto trigger on hourly basis, so we scheduled the script. As the script was to be scheduled one, we started creating SharePoint Apps to manage authentication. Register SharePoint Add-ins Go to <site collection url>/_layouts/15/AppRegNew.aspx by using a web browser. AppRegNew page form Enter values for the follow form fields: Add-in ID . Also known as client ID; a GUID that can be generated (when you select Generate ) or pasted into AppRegNew.aspx. The value must be unique for each add-in and must be lowercase .   Add-in Secret . Also known as the client secret, an opaque string. It is generated on the AppRegNew.aspx page by using the Generate button. Title:  A user-friendly title: for example, Contoso photo print