Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using a Powershell and CAML query to return items from a list. The list contains a "Group or People" field in which I have not seeing how to get the email and login information of the user. I assume I need to cast it to a SPUser object but have been unsuccessful so far. Anyone have an approach or snippet use?

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery = "<Where>...</Where>"
$spQuery.Query = $camlQuery;

$spListItems = $spList.GetItems($spQuery);

$spListItems |  Sort-Object Title | ForEach-Object -Process {

$spListItem[4]; # this returns display name only 

}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

With the help of this blog I found the answer. http://codingmode.com/category/uncategorized/

replace:

$spListItem[4]

with:

Get-UserEmail($spListItem.Fields[4].GetFieldValue($spListItem[4].ToString()))

add this function:

function Get-UserEmail([Microsoft.SharePoint.SPFieldUserValue]$SPFieldUserValue)
{
    $isNull = [String]::IsNullOrEmpty($SPFieldUserValue);
    if($isNull -eq $false){
        return $SPFieldUserValue.User.Email;
    }
    return $isNull;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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