1

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?

1 Answer 1

2

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;
8
  • 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
    Commented Aug 10, 2013 at 3:55
  • Yes it should. It contains two properties LookupValue and LookupId. Commented Aug 10, 2013 at 3:59
  • I'm having trouble with that. $lookup seems to be fetching null.
    – bgmCoder
    Commented Aug 10, 2013 at 4:00
  • Make sure are refencing correct, list, listitem and field Commented Aug 10, 2013 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
    Commented Aug 10, 2013 at 4:03

Your Answer

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

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