Setting DefaultColumnValue using PnP powershell Script with "&" or " ' " Symbol

Regular Visitor

Hi people! I am trying to set my choice column default value as "Folder with &" the script I am using is working fine for simple Text with no special characters but when it comes to this particular character it skips setting up the default column value for that folder 

 

$FolderList1 = Get-PnPFolderItem -FolderSiteRelativeUrl $DestinationLibraryName -ItemType Folder

foreach ($item in $FolderList1)
{
echo $item.Name
}

#Show the information of List
$List = Get-PnPList -Identity $DestinationLibraryName -Includes RootFolder.Folders

#Get All the FoldersPath in the List
$RootFolderURL = $List.RootFolder.Folders.ServerRelativeUrl
#Get the List items information
$ListItems = Get-PnPListItem -List $DestinationLibraryName
$Folders = $ListItems | Where {$_.FileSystemObjectType -eq "Folder"}

#Set the Default Value for Content Type Column level 1
ForEach($item in $FolderList1)
{

echo $DestinationLibraryName
echo $item.Id
echo $item.Name

Set-PnPDefaultColumnValues -List $DestinationLibraryName -Value $item.Name -Folder $item.Name -Field "ClientDocumentCategory"
}


# Set the Default Value for Content Type Column level 2
ForEach($item in $FolderList1)
{
$Level1Folder = $item.Name
$Level1folderPath = $DestinationLibraryName +"/"+ $Level1Folder

$Level1FolderList = Get-PnPFolderItem -FolderSiteRelativeUrl $Level1folderPath -ItemType Folder

Foreach($itemLevel1 in $Level1FolderList)
{
$ColumnValue = $itemLevel1.Name
$Path = $Level1folderPath
$L2FOLDER = $Level1Folder+ "/" + $ColumnValue

Set-PnPDefaultColumnValues -List $Path -Value $ColumnValue -Folder $L2FOLDER -Field "ClientDocumentType"

}
}

 

0 Replies