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
$item.Update()
}
}
}
portal_updateMemberUsername $lastname $firstname $logonname