On my portal I have a list with columns for First Name Last Name and Account where Account contains usernames.

So I have this function which reads through my list (it connects fine, it reads the list items), but it won't match correctly.

The write-host reports this:

Name=1;#My First Name;#1;My Last Name

Why is it adding the ;#1 to the return values? They clearly are not in the list values.

Here is my function:

function portal_updateMemberUsername([string]$whatlastname, $whatfirstname, $whatusername){
    $web = Get-SPWeb $portal_url
    #Get the SPList object to retrieve the list
    $list = $web.Lists[$portal_list]

    #Get all items in this list and save them to a variable
    $items = $list.items

    #Go through all items
    foreach($item in $items){
        write-host "Name= " $item["First Name"] $item["Last Name"]  #<----HERE
        if($item["Last Name"] -eq $whatlastname -and $item["First Name"] -eq $whatfirstname){
            [Microsoft.SharePoint.SPUser]$whatusername= $web.EnsureUser($whatusername)   
            $item["Account"] =  $whatusername

portal_updateMemberUsername $lastname $firstname $logonname

Ha ha! It was a Lookup field!

I tried it on a regular non-lookup field and it worked just fine.

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.