GitHub Icon Image
GitHub

Sample showing how to Extract the employees shown on modern pages (Author byline) in a selection of Site Collections to CSV

Summary

One of my customs requested that we removed a specific employee from the modern pages in their Intranet ASAP as that employee had left rather abruptly. They had no idea where that employee was displayed hence this script

Implementation

  • Open VS Code
  • Create a new file
  • Copy the code below,
  • Change the variables to target to your environment
  • Run the script.

Screenshot of Output

Example Screenshot

  • PnP PowerShell

# Author Kasper Larsen Fellowmind.dk
# Purpose : locate any Author byline and report the people displayed


$tenentUrl = "https://[Tenant].sharepoint.com"

Connect-PnPOnline -Url $tenentUrl -Interactive

#define which site collections you wish to iterate
#$relevantsitecollections = Get-PnPTenantSite | Where-Object {$_.template -eq "STS#3"}
$relevantsitecollections = Get-PnPTenantSite 

$Output = @()

foreach($site in  $relevantsitecollections)
{
    $sitecollectionUrl = $site.Url
    Write-Host "Url =  $sitecollectionUrl" -ForegroundColor Yellow
    Connect-PnPOnline -Url $sitecollectionUrl -Interactive
    $pages = Get-PnPListItem -List "sitePages" -ErrorAction SilentlyContinue
    
    foreach($page in $pages)
    {
        try 
        {
            $authorbyline = $page["_AuthorByline"]
            if($authorbyline)
            {
                $myObject = [PSCustomObject]@{
                    URL     = $tenentUrl+$page["FileRef"]
                    Email = $authorbyline.Email
                    Name = $authorbyline.LookupValue
                    errorcode = ""

                }        
                $Output+=($myObject)
            }
        }
        catch 
        {
            $myObject = [PSCustomObject]@{
                URL     = $tenentUrl+$page["FileRef"]
                personid = ""
                personupn = ""
                errorcode = $_.Exception.Message

            }        
            $Output+=($myObject)
        }
    }
}
$Output | Export-Csv  -Path c:\temp\AuthorbylineUsers.csv -Encoding utf8BOM -Force  -Delimiter "|"

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?

Contributors

Author(s)
Kasper Larsen, Fellowmind

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI