Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm looking for a powershell script that allows me to set the default value for a column in SharePoint. Thanks

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

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:

enter image description here

Enjoy! :)

share|improve this answer
add comment

Check this blog post Use PowerShell to Manage Lists, Views, and Items in SharePoint on how to update SPListItem via PowerShell.

Sample:

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()
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.