SharePoint Online : Get List settings properties using PowerShelll

 Requirement : Loop through all subsite and site collection to get list settings properties.


List Settings

**********************************************************************************************************************
#######################################################################################

$Username = "ABC@domain-name.com"

$Password = ConvertTo-SecureString -String "*******" -AsPlainText -Force

$Credentials = New-Object System.Management.Automation.PSCredential ($Username, $Password)

$targetWeb = "https://abc.sharepoint.com/sites/sitecollection" ## URL of the site you are uploading to

$clientid = "abc-abc-abc-abc-abc" #Add client id of site

$clientsecret = "abcdefghijklmnopq=" #Add client secret of site

#########################################################################################

try {
Connect-PnPOnline -Url $targetWeb -AppId $clientid -AppSecret $clientsecret

Write-Host "Connection to site established: " $targetWeb
}
catch {
Write-Error $_
}

Try {
    #Function to Get all lists from the web
    Function Get-SPOList($Web)
    {
        #Get All Lists from the web
        $Lists = $Web.Lists
        $Context.Load($Lists)
        $Context.ExecuteQuery()

        #Get all lists from the web  
        ForEach($List in $Lists)
        {
           $Context.Load($List)
           $Context.ExecuteQuery()
   
     #Get List Properties: Title, Description
    Write-host -f Yellow "---  General Settings ---"
    Write-host "List Title:" $List.Title
    Write-host "List Description:" $List.Description
    Write-host "Show in Quick Launch:" $List.OnQuickLaunch
 
    Write-host -f Yellow "--- Versioning settings ---"
    Write-host "Content Approval Enabled:" $List.EnableModeration
    Write-host "Versioning Enabled:" $List.EnableVersioning
    Write-host "Major Versions Limit:" $List.MajorVersionLimit
    Write-host "Minor Versions Enabled:" $List.EnableMinorVersions
    Write-host "Minor Versions Limit:" $List.MajorWithMinorVersionsLimit       
    Write-host "Draft Versions Security:" $List.DraftVersionVisibility
    Write-host "Require Checkout:" $List.ForceCheckout  #In Document Libraries
 
    Write-host -f Yellow "--- Advanced settings ---"
    Write-host "Content Type Enabled:"$List.ContentTypesEnabled
    Write-host "Attachments Enabled:"$List.EnableAttachments
    Write-host "New Folders Command Available:"$List.EnableFolderCreation
    Write-host "No Crawl Flag:"$List.NoCrawl
   Write-host "Offline Availability:"$List.ExcludeFromOfflineClient
    Write-host "List Experience:"$List.ListExperienceOptions
     
    #Other hidden Settings
    Write-host -f Yellow "--- Other settings ---"
    Write-host "List ID:"$List.ID
    Write-host "List Created On:"$List.Created
    Write-host "Last Item Deleted On:"$List.LastItemDeletedDate
    Write-host "Last Item Modified On:"$List.LastItemModifiedDate
    Write-host "List Item Count:"$List.ItemCount
    Write-host "Is Hidden List:"$List.Hidden
    Write-host "Document Template:"$List.DocumentTemplateUrl #In Document Libraries
    Write-host "List Type:"$List.BaseType
         }
        }
    }

    #Function to get all webs from given URL
    Function Get-SPOWeb($WebURL)
    {
        #Set up the context
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
        $Context.Credentials = $Credentials

        $Web = $context.Web
        $Context.Load($web)
        #Get all immediate subsites of the site
        $Context.Load($web.Webs) 
        $Context.ExecuteQuery()

        #Call the function to Get Lists of the web
        Write-host "Processing Web :"$Web.URL -f Yellow
        
        Get-SPOList $Web

        #Iterate through each subsite in the current web
        foreach ($Subweb in $web.Webs)
        {
            #Call the function recursively to process all subsites underneaththe current web
            Get-SPOWeb($SubWeb.URL)
        }
    }

    #Call the function to get all sites
    Get-SPOWeb $SiteUrl
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

**********************************************************************************************************************

Comments

Popular posts from this blog

SharePoint online - 'Load More' button click event to show more items using PnPjs

SPFx - Display export buttons for Excel, CSV, PDF, Copy, Print, Column visibility in Datatable.net using Typescript

Rest API for Delete Yammer Comments