sharepoint on premise – Looping through all documents in a site through powershell script


I’m new to powershell and trying to loop through all document libraries of a site using below code:

$webs = (Get-SPSite “XXX” | Get-SPWeb -Limit all -ErrorAction SilentlyContinue)

$Lists = $webs.Lists

$ListItemCollection = @()

Foreach($List in $Lists) {

if($List.BaseType -eq "DocumentLibrary"){


    $list.Items | Where-Object { $_("Choice Column") -eq $null } | foreach {
    

        $ExportItem = New-Object PSObject
        $ExportItem | Add-Member -MemberType NoteProperty -name "URL" -value $_.URL
        $ExportItem | Add-Member -MemberType NoteProperty -name "Name" -value $_("Name")
        $ListItemCollection += $ExportItem
    }
}
}

$ListItemCollection | Export-CSV “D:TestLogs.txt” -NoTypeInformation

The output in txt file contains those files also which doesn’t have the custom column(Choice Column).
Do I need to check if the Document library contains the custom field and if so how can i check it.

Please note we are using Sharepoint 2016 on-premise.

Thanks.