I want to send daily reminders to users who have tasks assigned to them. It seems like a simple way to do this would be to write a Powershell script that sends an email for each item, and set up a scheduled task to run the script once a day. However, the script below returns something like 1;#John Doe (full name) for each item.

Is there a way to get the user's email address, or Windows username, from the task list item using Powershell? I think there must be, since SharePoint is able to send mail to the assignee when the task is created.

$web = Get-SPWeb http://mysharepointsite
$list = $web.Lists["Task List Test"]    
foreach ($item in $list.items)
    if ($item["Status"] -ne "Completed")
        write-host $item["Assigned To"]

1 Answer 1


Script returns lookup value. So you can parse the num part of that string - user ID and then find it by command


whole script:

$value = "1;#user name";

$arr = $value.Split(";#");
$parsedId = $arr[0];
$user = $web.Users.GetById($parsedId);

write-host "mail:" $user.Email
  • That script has a couple of problems: 1) $arr[0] returns the part before the delimiter. Should be $arr[2]. 2) Once fixed, it returns John Doe, AKA full name, not username. Do you know of a way to get the username?
    – LFurness
    Jan 16, 2013 at 18:58
  • 1
    Script returns user ID ($arr[0]) and then you query for $user by ID. If you want login name, just type $user.LoginName;
    – luccio
    Jan 16, 2013 at 20:51
  • Maybe I'm missing something, but for me $arr[0] returns 1.
    – LFurness
    Jan 16, 2013 at 20:53
  • 1
    And that is supposed to be user id. Lookup column consists of ID;#display name
    – luccio
    Jan 16, 2013 at 20:55
  • Thanks for explaining. I'm getting an error with Users.GetById. If I can resolve that, I'll mark this as the anwer. ---- Exception calling "GetByID" with "1" argument(s): "U At C:\powershell\taskListEmail2.ps1:22 char:28 + $user = $web2.Users.GetById <<<< ($parsedId) + CategoryInfo : NotSpecified: (:) [], + FullyQualifiedErrorId : DotNetMethodException
    – LFurness
    Jan 17, 2013 at 19:35

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.