0

I have strings like

$value = "1;#Mohapatra,Mrutyunjaya (ADM) 10;#Sumit Upadhyay(ADM) 11;#Naidu,Ishan(ADM)"

I want to retrieve

"Mohapatra,Mrutyunjaya (ADM)", "Sumit Upadhyay(ADM)", "Naidu,Ishan(ADM)" 

from $value.

I have tried $value.Split(";#")[0]. It is returning the first parameter only. But I want all the parameters

4
  • 2
    Is there something you have tried we can help you fix? It is expected that you have tried something first that we can help you fix. Commented Nov 19, 2015 at 13:49
  • I had used $value.Split(";#")[0]. It is returning the first parameter only. But I want all the parameters Commented Nov 19, 2015 at 13:54
  • try $value.split('#').replace(';', '') Commented Nov 19, 2015 at 13:58
  • How are you obtaining the string of user values? Since you tagged the question with SharePoint-2010, I'm guessing these strings that you're trying to parse are values from a person or group field. In Powershell, you can access the values of a multi-select person or group field directly, using the format of $item["Field"][i].LookupValue or $item["Field"][i].User.DisplayName where i is an index greater than or equal to 0 and less than $item["Field"].Count, $item is a list item, and Field is the internal name of the column you're accessing. Commented Nov 19, 2015 at 16:15

2 Answers 2

3

Split your string at sequences of \s*\d+;# (optional whitespace, followed by a number, a semicolon, and a hash character), and remove empty elements from the resulting list:

$value -split '\s*\d+;#' | Where-Object { $_ }
Sign up to request clarification or add additional context in comments.

Comments

1

Just FYI, if you want to declare each as a variable you can say $a,$b,$c,$d = $Value -Split (";#") and each of $a, $b, $c and $d will retain those values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.