Domanda

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

È stato utile?

Soluzione

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
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top