Get the selected values from a multiselect field via PowerShell

Another quest in Sharepoint automatization is to get the selected values for a given multiselect field. We could start in the usual way as to get the given item from the list then check the field value.

So in SharepointLand multiselect values are stored in a string spearated by a “#” sign. Just that is the trick. So when we would like to work with these data first this string should be split into small elements. So here we are the string example for the field value containing multiselectvalues: ;#one;#two;#three;#

The next script is for getting these values to an array (in that example we already have the list item got to a variable)
An article has been already written about how to create a PWS script which connect to a Sharepoint List and get’n’update the List items in it.

$array = @()
$bool = $true
$counter = -1
$Multiselectvalues = $item["Multiselect_field"]
$text = $Multiselectvalues.tostring()
while ($bool -eq $true) {
$text = $text.substring(2,$text.length-2)
if ($text.length -lt 2)  #we are at the end of the values-list
{ $bool = $false }
else { #insert the next value to the array
$array +=  @($counter)
$array[$counter] = $text.substring(0,$text.indexof(";#"))
$text = $text.substring($tex.indexof(";#"),$text.length-$text.indexof(";#"))

Have a nice weekend! 😀


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s