SharePoint Online: Get Email, Display Name, Login ID from “Created By” Column in PowerShell

Requirement: Get User Name, Email, Login ID, etc from “Created By” field value of a List Item using PowerShell

PowerShell to Retrieve User Object from “Created By” Field:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables for Processing
$SiteURL = ""
$ListName = "Projects"
$ItemID = "1"

#Get Credentials to connect
$Cred = Get-Credential

Try { 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the List Item
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $ListItem = $List.GetItemById($ItemId)

    #Get the "Created By" column value of the Item
    $CreatedBy = $ListItem.FieldValues["Author"]

    #Get the User Object
    $User = $Ctx.Web.GetUserById($CreatedBy.LookupId)

    $User | Select Email, Title, LoginName   
Catch {
    write-host -f Red "Error:" $_.Exception.Message

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply