Wednesday, July 17, 2013

SharePoint SPFieldChoice change selected value Powershell

I have a dropdownlist with below items

Item1
Item2
Item3
Item4

When you run below script it will update dropdown list selected value as "Item4" for all sharepoint list items.


            foreach ($item in $items)
            {
           
             $field = [Microsoft.SharePoint.SPFieldChoice]$item.Fields["DOC GROUP"];
             # Write-Host "ID" $field.id
             write-host "Choice Field:" $item.url  $field.Choices[3]
             $item["DOC GROUP"] =  $field.Choices[3]
             $item.SystemUpdate()  

#foreach ($str in $field.Choices)
                #{
                 #  Write-Host  $str;

               # }
            }
                                

No comments:

Post a Comment

Followers