0

I am writing a script for assigning the default value of a column in SharePoint library:

$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$sList.Fields.Add("OpCoNam",$spFieldType,$true)
$sList.Fields["OpCoNa"].DefaultValue="$sList.Title"
$sList.Update()

But no value is getting added.

1 Answer 1

1

You should update the field as below

$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$sList.Fields.Add("OpCoNam",$spFieldType,$true)
$sList.Update()

$f = $sList.Fields["OpCoNam"]
$f.DefaultValue = "DefaultValue"
$f.Update()
2
  • Amal: thanks it is working but the column created is a mandatory value column. Any way to make it non-mandatory? Commented Mar 20, 2015 at 14:04
  • 1
    Yes, pass $false to Add method Commented Mar 20, 2015 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.