Question

I am trying to get the user Email through a LookUpField. When I try to "Write-Host the Email", the screen is blank. There is no errors and nothing. What is wrong with my code? Any help is much appreciated.

    ForEach ($ListItem in $ListItems){

    $lookUpField = $ListItem["uQmsResponsible"] -as [Microsoft.SharePoint.Client.FieldLookupValue]       
    $user = $Web.EnsureUser($lookUpField.LookupValue.DisplayName);
    Write-Host $user.Email -ForegroundColor Cyan


}

EDIT

Picture of the listSettings(columns) for the list "Roller" that the LookupField "uQmsResponsible" is referencing : enter image description here

Picture of what Lookupfield returns:

enter image description here

Était-ce utile?

La solution

Judging by the name of your column (uQmsResponsible) I guess it is of type "Person or Group". If that is the case, you should not cast your variable to FieldLookupValue, but to FieldUserValue. You could try with this code:

ForEach ($ListItem in $ListItems)
{
    $lookUpField = $ListItem["uQmsResponsible"] -as [Microsoft.SharePoint.Client.FieldUserValue]
    Write-Host $lookUpField.Email -ForegroundColor Cyan
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top