In my powershell script, I have a method that fetches a username from a sharepoint list. This works fine - my problem is that field is from a lookup column. The user chooses the username from a lookup column.

That means that the usernames are returned to my script as strings, but with a 10;# prepended to the username where the 10 is the id of the item in the lookup's source list (I think).

But I need to have a clean username, without the 10;# prepended.

How can I get that?


Here is an example:

$Web = Get-SPWeb "http://yoursite"
$List = $Web.Lists["Listname"]
$Item = $List.Items[0];
$Lookup = new-object Microsoft.SharePoint.SPFieldLookupValue($Item["YourField"])
$User = $Lookup.LookupValue;
  • So you would tell me that using the $Lookup that way would return the real lookup value instead of the funny return string? I'll try that out. – bgmCoder Aug 10 '13 at 3:55
  • Yes it should. It contains two properties LookupValue and LookupId. – Nadeem Yousuf Aug 10 '13 at 3:59
  • I'm having trouble with that. $lookup seems to be fetching null. – bgmCoder Aug 10 '13 at 4:00
  • Make sure are refencing correct, list, listitem and field – Nadeem Yousuf Aug 10 '13 at 4:03
  • Uh, never mind that. It's supposed to be null when the field is empty... Thanks! It works! I appreciate it a bunch, fellow. – bgmCoder Aug 10 '13 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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