I have code in PowerShell that export a Sharepoint list to excel. Only I have a few Sharepoint Lists that has "/" sign in it. My code can not store a file that has a / in it. Is it possible to get a Sharepoint List with a / in it and change it to the minus "-" sign to save the file. Or just remove the / in the filename.
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() | Where-Object { $.Key -in $Global:selectProperties } |
ForEach-Object {
if( $.Key -eq 'Datum' )
{
$obj | Add-Member Noteproperty $.Key $.Value.ToLocalTime().ToString("dd-MM-yyyy")
}
else
{
$obj | Add-Member Noteproperty $.Key $.Value
}
}
$hashTable+=$obj;
$obj=$null;
}$hashtable | Export-XLSX $outputFilePath -Table -Autofit -Force}catch [Exception]{$ErrorMessage = $_.Exception.MessageWrite-Host "Error: $ErrorMessage" -ForegroundColor Red}}
ExportList("Dit is mijn lijst / map"); <==========