SharePoint Online: Nhận Email, Tên hiển thị, ID đăng nhập từ Cột "Được tạo bởi" trong PowerShell
Yêu cầu: Nhận Tên người dùng, Email, ID đăng nhập, v.v. từ giá trị trường “Được tạo bởi” của Mục danh sách bằng PowerShell.
PowerShell để truy xuất đối tượng người dùng từ trường “Được tạo bởi”:
Bạn đã bao giờ muốn lấy Email của người dùng đã tạo một mục trong SharePoint Online ở giữa tập lệnh PowerShell chưa?
#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 = "https://crescent.sharepoint.com/sites/PMO"
$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)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()
#Get the "Created By" column value of the Item
$CreatedBy = $ListItem.FieldValues["Author"]
#Get the User Object
$User = $Ctx.Web.GetUserById($CreatedBy.LookupId)
$Ctx.Load($User)
$Ctx.ExecuteQuery()
$User | Select Email, Title, LoginName
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
PnP PowerShell để nhận email của người dùng đã tạo tài liệu
Làm cách nào để nhận được email từ các tài liệu đã tải lên? Hãy truy xuất email của người dùng đã tải tệp lên thư viện tài liệu SharePoint Online.
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Branding"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get All Files from the document library - In batches of 500
$Files = Get-PnPListItem -List $ListName -PageSize 500 | Where {$_.FileSystemObjectType -eq "File"}
#Loop through all documents
$DocumentsData=@()
ForEach($File in $Files)
{
#Collect Documents Data
$DocumentsData += New-Object PSObject -Property @{
FileName = $File.FieldValues.FileLeafRef
URL = $File.FieldValues.FileRef
AuthorEmail = $File.FieldValues.Author.Email
}
}
#Get Files Data
$DocumentsData