I'm looking for a powershell script that allows me to set the default value for a column in SharePoint. Thanks
The main point here is that you can work with SharePoint Object Model from PS. So, your task is just to find out the way to change default field value using SharePoint Object Model, and translate it to PS notation.
The default value for a column in SharePoint object model is set using SPField.DefaultValue property.
So, let's try use this knowledge in PS. I have SampleList2 of type Contacts on my local SharePoint portal, and will try to change default value for a 'First Name' field.
Below is my PowerShell script:
$w = Get-SPWeb http://localhost $l = $w.GetListFromUrl("/Lists/SampleList2/AllItems.aspx") $f = $l.Fields["First Name"] $f.DefaultValue = "my default name" $f.Update()
Let's try to create new item using GUI now:
Check this blog post Use PowerShell to Manage Lists, Views, and Items in SharePoint on how to update SPListItem via PowerShell.
We can assign additional values to fields as well. In the next example, we add values to the TextField and ChoiceField, which we created earlier in this example:
PS > $spListItem["TextField"] = "Hey hey" PS > $spListItem["ChoiceField"] = "First Choice" #Finally, we use the Update() method to create the new list item: PS > $spListItem.Update()