0

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 

}

2 Answers 2

3

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;
}
2
$personFieldValue = $ListItem["PersonFieldName"].ToString();            
$spFieldUserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($oWeb,$personFieldValue); 

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.