Forum Discussion
Rafia25000
Nov 08, 2022Copper Contributor
Setting DefaultColumnValue using PnP powershell Script with "&&" or " ' " Symbol
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 c...
Varun_Ghildiyal
Mar 08, 2023Iron Contributor
To set the default value of a choice column with special characters like "&" in PowerShell, you need to use escape characters. In PowerShell, the escape character is the backtick (`), which can be used to escape special characters.
So, to set the default value of a choice column to "Folder with &", you can modify your script like this:
# Set the Default Value for Content Type Column level 1
ForEach($item in $FolderList1) {
$defaultValue = "Folder with `&"
Set-PnPDefaultColumnValues -List $DestinationLibraryName -Value $defaultValue -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) {
$defaultValue = "Folder with `&"
$ColumnValue = $itemLevel1.Name
$Path = $Level1folderPath
$L2FOLDER = $Level1Folder+ "/" + $ColumnValue
Set-PnPDefaultColumnValues -List $Path -Value $defaultValue -Folder $L2FOLDER -Field "ClientDocumentType"
}
}Note that we're using the backtick (`) to escape the "&" character in the default value variable.