Is this what you're trying to do?
$Global:selectProperties = @("Datum", "00:00 - 07:59", "08:00 - 16:59", "17:00 - 23:59", "Opmerkingen");
function ExportList($listName) {
try {
$listItems = (Get-PnPListItem -List $listName -Fields $Global:selectProperties).FieldValues
$outputFilePath = "c:\Temp\" + $listName + ".xlsx"
$hashTable = @()
foreach ($listItem in $listItems) {
$obj = New-Object PSObject
$listItem.GetEnumerator() |
ForEach-Object{
if ($Global:selectProperties -contains $_.Key){
if ($_.Key -eq 'Datum'){
$v = "{0:dd-MM-yyyy}" -f ([datetime]($_.Value)).ToLocalTime()
}
else{
$v = $_.Value
}
$obj | Add-Member Noteproperty $_.Key $v
}
$hashTable += $obj;
$obj = $null;
}
$hashtable | Export-XLSX $outputFilePath -Table -Autofit -Force
}
catch [Exception] {
$ErrorMessage = $_.Exception.Message
Write-Host "Error: $ErrorMessage" -ForegroundColor Red
}
}