I have two almost identical calculated fields that I want to add to a list on several sites through Powershell .
"Calculated risk" formula:
=Konsekvens*Sandsynlighed
"Revised calculated risk" formula:
=[Revideret konsekvens]*[Revideret sandsynlighed]
Trying to add the first column "Calculated risk" will work. However, "Revised calculated risk" with the above mentioned formula will fail on the current line of code:
$riskList.Fields.Add($site.RootWeb.Fields["Beregnet revideret risiko"])
It throws this error:
The formula refers to a column that does not exist...
I am using the following PowerShell code-snippet for both columns:
$calcRiskField = $riskList.Fields["Beregnet risiko"]
if($calcRiskField -eq $null) {
$riskList.Fields.Add($site.RootWeb.Fields["Beregnet risiko"])
Write-Host Added Beregnet risiko field -ForegroundColor Yellow
}
$calcRevisedRiskField = $riskList.Fields["Beregnet revideret risiko"]
if($calcRevisedRiskField -eq $null) {
$riskList.Fields.Add($site.RootWeb.Fields["Beregnet revideret risiko"])
Write-Host Added Beregnet revideret risiko field -ForegroundColor Yellow
}
I have checked to see if the columns exist on the list and they do. I have checked to see if SharePoint UI throws any errors in the formular and it does not. I have tried to add the column through SharePoint UI and that works fine.
The error seems to be connected to the formula where the two columns have spaces in the display name, since it works for calculated columns where the display names are one word.
Any ideas?