Get User E-mail Address from List Item “Created By” using PowerShell
For a PowerShell automation work, I had to retrieve the Email ID of the user who has created a particular list item. Here is the nifty PowerShell script to retrieve E-mail ID from created by field:
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
#Function to get User's Email from User ID
Function GetUserEmail($UserValue)
{
#Uservalue: E.g: "1;#user name";
$arr = $UserValue.Split(";#");
$UserID = $arr[0];
$user = $web.SiteUsers.GetById($UserId);
#the above line returns: SPUser Object
return $user.Email
}
$WebURL ="https://sharepoint.crescent.com/SharePointSupport/"
$ListName ="Site Requests"
#Get the Web and List
$Web = Get-SPWeb $WebURL
$list = $web.Lists[$ListName]
#Get an Item by id
$item = $list.GetItemByID(1)
#Get Created by User details
#$item["Author"] Returns something like: 3;#Salaudeen
$CreatorMail = GetUserEmail($item["Author"])
Write-Host $CreatorMail
The same thing can also be done in C# to get user email addresses programmatically.
Hi,
How can we find a specific email address (eg: abc@gmail.com) located anywhere under a site collection? eg: in any list, items, comments column, etc.? Is there a way to find?
Thanks,
CS
You can generate a Permission Report for a site: SharePoint 2013 / 2016: Specific User Permission Analysis Report using PowerShell, Make sure you remove the “$_.HasUniqueRoleAssignments -eq $True” condition to include all items.