I have a Site collection with 50 Lists and Libraries . Is there any powershell script that iterates through all lists and get its content type , Views,View Properties in a CSV file.

I tried like this but the order in my csv is not proper.

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

#Variables for Processing
$SiteUrl = "https://test.sharepoint.com/sites/PGDCA"
$Password ="123456"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$ct = @();
$systemlibs = @("Data Connections Test","Images","Pages","Site Assets", "Site Collection Documents","Site Collection Images", "Site Pages", "Style Library","Tasks","test","Test Library","TestForm","Workflow Tasks")
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials

    #Set up the context

    #Get All Lists
    $Lists = $Context.web.Lists

    #Iterate through each list in a site  
    forEach($List in $Lists)
        if($List.Hidden -eq $false)
            if(-not ($systemlibs -Contains $List.Title))
                #Write-Host $List.Title
                $ListTitle = $List.Title
                GetSPListView $Context $ListTitle
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red

function GetSPListView ($Context, $ListName)
    #Write-Host "This is My"$ListName

    $spList = $Context.Web.Lists.GetByTitle($ListName);

    foreach($Listview in $spList.Views)

        if($Listview.Hidden-eq $false)
            Write-Host $ListName ":" $Listview.Title ":" $Listview.ViewFields 
  • Hi. You are mixing CTs and Views in one bowl - as they are not related, You should collect information separately. One run looking for content types, other for views. – Kristaps Vilerts Aug 2 '18 at 8:04
  • I was able to get all the views along with the fields. However i was unable to store all of them in CSV file. but i was bale to do it in Write-host I have updated my code in the orginal. – santosh kondapalli Aug 2 '18 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.