Getting LookupField with SharePoint Online Management Shell
-
09-01-2021 - |
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 :
Picture of what Lookupfield returns:
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