SharePoint Online: Find Site Column Usage in Lists and Libraries using PowerShell

Requirement: Find a Site Column usage in SharePoint Online Site Collection

SharePoint Online: PowerShell to Get a Site Column’s usage in lists and libraries of a Site Collection:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to get a particular Site column usage in Lists and Libraries
Function Find-SPOSiteColumnUsage([String]$SiteURL, [String]$SiteColumnInternalName)
        Write-host -f Yellow "Processing Site:" $SiteURL

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        #Get All Lists and Libraries of the Web

        #Get the site column
        $SiteColumn = $Ctx.Web.Fields | where {$_.InternalName -eq $SiteColumnInternalName}
        if($SiteColumn -ne $NULL)
            #Loop through each List Field
            ForEach($List in $Ctx.Web.Lists)
                Write-host -f Yellow "`t `t Scanning List $($List.Title)"

                ForEach($Field in $List.Fields)
                    If($Field.Id -eq $
                        Write-host -f Green "`t `t Found the Site Column in List '$($List.Title)' at Site '$($SiteURL)'"

        #Iterate through each subsite of the current web
        foreach ($Subweb in $Ctx.web.Webs)
            #Call the function recursively
            Find-SPOSiteColumnUsage $Subweb.url $SiteColumnInternalName
    Catch {
    write-host -f Red "Error Generating Site Column Usage Report!" $_.Exception.Message

#Config Parameters

#Get Credentials to connect
$Cred= Get-Credential

#Call the function to get the Site Column usage
Find-SPOSiteColumnUsage $SiteURL $SiteColumnInternalName 

This script gets a particular site column’s usage in lists and libraries and prints the finding as below:

powershell to find site column usage in sharepoint online

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply