Answered by:
Choice options in a choice field column

Question
-
Dear All,
I have following script which inserts a new choice column in all the libraries of a site.
Get-SPWeb -site http://sp2010:8080/personal/rakhishma -Limit All | foreach {
$doclibtype = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$doclibs = $_.GetListsOfType($doclibtype)
$doclibs.Count
for ($i=0; $i -lt $doclibs.Count; $i++)
{
$doclib = $doclibs[$i]
$doclib.Title
$fieldtype = [Microsoft.SharePoint.SPFieldType]::Choice
$doclib.Fields.Add(“Choice Column”,$fieldtype,$false)
$doclib.Update()
$view = $doclib.Defaultview
$view.viewFields.Add("Choice Column")
$view.Update()
}
}Now, my question is how to insert choices like choice1, choice2 , choice3 into choice column using powershell...?
Wednesday, July 11, 2012 8:57 AM
Answers
-
Sure Al.....This is the solution for the problem I mentioned :
Get-SPWeb -site http://eismosstest001:10101 -Limit All | foreach {
$doclibtype = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$doclibs = $_.GetListsOfType($doclibtype)
$doclibs.Count
for ($i=0; $i -lt $doclibs.Count; $i++)
{
$doclib = $doclibs[$i]
$doclib.Title
$Choices = New-Object System.Collections.Specialized.StringCollection
$Choices.Add("choice1")
$Choices.Add("choice2")
$Choices.Add("choice3")
$Choices.Add("choice4")
$Choices.Add("choice5")
$Choices.Add("choice6")
$fieldtype = [Microsoft.SharePoint.SPFieldType]::Choice
$doclib.Fields.Add(“Choice column”,$fieldtype,$false,$false,$choices)
$doclib.Update()
$view = $doclib.Defaultview
$view.viewFields.Add("Choice column")
$view.Update()
}
}
- Marked as answer by Yan Li_ Tuesday, July 17, 2012 5:53 AM
Thursday, July 12, 2012 5:27 AM
All replies
-
got the solution....please ignore this postWednesday, July 11, 2012 2:50 PM
-
got the solution....please ignore this post
Why don't you share your solution for others that might find it useful?
Al Dunbar
Wednesday, July 11, 2012 4:34 PM -
Sure Al.....This is the solution for the problem I mentioned :
Get-SPWeb -site http://eismosstest001:10101 -Limit All | foreach {
$doclibtype = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$doclibs = $_.GetListsOfType($doclibtype)
$doclibs.Count
for ($i=0; $i -lt $doclibs.Count; $i++)
{
$doclib = $doclibs[$i]
$doclib.Title
$Choices = New-Object System.Collections.Specialized.StringCollection
$Choices.Add("choice1")
$Choices.Add("choice2")
$Choices.Add("choice3")
$Choices.Add("choice4")
$Choices.Add("choice5")
$Choices.Add("choice6")
$fieldtype = [Microsoft.SharePoint.SPFieldType]::Choice
$doclib.Fields.Add(“Choice column”,$fieldtype,$false,$false,$choices)
$doclib.Update()
$view = $doclib.Defaultview
$view.viewFields.Add("Choice column")
$view.Update()
}
}
- Marked as answer by Yan Li_ Tuesday, July 17, 2012 5:53 AM
Thursday, July 12, 2012 5:27 AM -
Sure Al.....This is the solution for the problem I mentioned :
Get-SPWeb -site http://eismosstest001:10101 -Limit All | foreach {
$doclibtype = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$doclibs = $_.GetListsOfType($doclibtype)
$doclibs.Count
for ($i=0; $i -lt $doclibs.Count; $i++)
{
$doclib = $doclibs[$i]
$doclib.Title
$Choices = New-Object System.Collections.Specialized.StringCollection
$Choices.Add("choice1")
$Choices.Add("choice2")
$Choices.Add("choice3")
$Choices.Add("choice4")
$Choices.Add("choice5")
$Choices.Add("choice6")
$fieldtype = [Microsoft.SharePoint.SPFieldType]::Choice
$doclib.Fields.Add(“Choice column”,$fieldtype,$false,$false,$choices)
$doclib.Update()
$view = $doclib.Defaultview
$view.viewFields.Add("Choice column")
$view.Update()
}
}
Thursday, July 12, 2012 5:27 AM