Forum Discussion
childishbambino
May 31, 2023Copper Contributor
how to use powershells sharepoint PnP module change columns conditional formulas?
In sharepoinm, I have a custom formula for a column , called column A, that looks like this: =if[$myColumnB],'true','false') I need to do this 200 times, with different columns, how do I use ...
dperez13
Jun 01, 2023Copper Contributor
disregard, okay, now how do I acesss the sharepoint list that I want to make these chages on?
Import-Module -Name PnP.PowerShell -Debug -Force
Connect-PnPOnline -Url
$site =
$sharedDocumentsURL = $site+"/Shared Documents"
$sharedFiles = Get-PnPListItem -List "Shared Documents"
foreach ($file in $sharedFiles) {
Write-Host "File name: $($file["FileLeafRef"])"
}
I have this, but i do not care about the shared documents, I need to access the SPO list so I can use your code on it, how doI do this?
Import-Module -Name PnP.PowerShell -Debug -Force
Connect-PnPOnline -Url
$site =
$sharedDocumentsURL = $site+"/Shared Documents"
$sharedFiles = Get-PnPListItem -List "Shared Documents"
foreach ($file in $sharedFiles) {
Write-Host "File name: $($file["FileLeafRef"])"
}
I have this, but i do not care about the shared documents, I need to access the SPO list so I can use your code on it, how doI do this?
ganeshsanap
Jun 01, 2023MVP
dperez13 Use this code:
$siteUrl = "https://contoso.sharepoint.com/sites/siteName"
Connect-PnPOnline -Url $siteUrl -Interactive
$conditionalFormula = "=if[{0}],'true','false')" -f '$myColumnB'
# Get SP list field
$field = Get-PnPField -List "Tasks" -Identity "ColumnA"
# Apply conditional formula to column
$field.ClientValidationFormula = $conditionalFormula
$field.Update()
Invoke-PnPQuery
Replace siteUrl variable value with URL of your SharePoint site and use display name of your list in place of Tasks (in above code).
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.