0

Hi I am using this script to return all documents in a site collection. I have some custom columns in the library but I am unsure how to add them to the script, specifically the internal name. Is there a way to get all column names so that I can put them in the csv ?

#Connect to SPO
Connect-PnPOnline -Url "https://site.sharepoint.com/sites/07/li" 
#Store in variable all the document libraries in the site
$DocLibrary = Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 } 
$LogFile = "C:\users\$env:USERNAME\Desktop\SPOFolders.csv"
$results = @()
foreach ($DocLib in $DocLibrary) {
    #Get list of all folders in the document library
    $AllItems = Get-PnPListItem -PageSize 1000 -List $DocLib -Fields "SMTotalFileStreamSize", "Author"
    
    #Loop through each files/folders in the document library for folder size = 0
    foreach ($Item in $AllItems) {
       # if ((([uint64]$Item["SMTotalFileStreamSize"]) -eq 0)) {
            Write-Host "Empty folder:" $Item["FileLeafRef"] -ForegroundColor Yellow
    
            #Creating object to export in .csv file
            $results += [pscustomobject][ordered] @{
                CreatedDate      = [DateTime]$Item["Created_x0020_Date"]
                FileName         = $Item["FileLeafRef"] 
                CreatedBy        = $Item.FieldValues.Author.LookupValue
                ContentType      = $Item["ows_ContentType"]
                FilePath         = $Item["FileRef"]
                SizeInMB         = ($Item["SMTotalFileStreamSize"] / 1KB).ToString("N")
                LastModifiedBy   = $Item.FieldValues.Editor.LookupValue
                EditorEmail      = $Item.FieldValues.Editor.Email
                LastModifiedDate = [DateTime]$Item["Modified"]
                CaseManager      = $Item["Case_x0020_Manager"].Email)
            }
        }#end of IF statement
    }
#}
$results | Export-Csv -Path $LogFile -NoTypeInformation

1 Answer 1

0

You could use the below command to get all columns in the library:

Get-PnPField -List "<Library Name>"

enter image description here

Reference: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnpfield?view=sharepoint-ps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.