Tuesday, November 26, 2024

Power shell Script to get all lists and library columns and it's type to export into CSV from a Sharepoint 2013/2016 site collection and its subsites.

 


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


# Configuration Parameters

$SiteURL = "https://intranet.crescent.com/sites/test"

$CSVPath = "D:\AllFields.csv"


# Get the Web

$Web = Get-SPWeb $SiteURL


# Create a DataTable to store the fields information

$DataTable = New-Object System.Data.DataTable

$DataTable.Columns.Add("ListTitle") | Out-Null

$DataTable.Columns.Add("FieldTitle") | Out-Null

$DataTable.Columns.Add("InternalName") | Out-Null

$DataTable.Columns.Add("FieldType") | Out-Null

$DataTable.Columns.Add("IsHidden") | Out-Null


# Iterate through each list and library

foreach ($List in $Web.Lists) {

    foreach ($Field in $List.Fields) {

        $Row = $DataTable.NewRow()

        $Row["ListTitle"] = $List.Title

        $Row["FieldTitle"] = $Field.Title

        $Row["InternalName"] = $Field.InternalName

        $Row["FieldType"] = $Field.TypeDisplayName

        $Row["IsHidden"] = $Field.Hidden

        $DataTable.Rows.Add($Row)

    }

}


# Export the DataTable to a CSV file

$DataTable | Export-Csv -Path $CSVPath -NoTypeInformation


# Dispose of the web object

$Web.Dispose()


Write-Host "All fields exported successfully to $CSVPath"


No comments:

Post a Comment