SharePoint Online: PowerShell เพื่อรับโปรไฟล์ผู้ใช้ทั้งหมด
ความต้องการ: รับโปรไฟล์ผู้ใช้ทั้งหมดใน SharePoint Online โดยใช้ PowerShell
จะรับโปรไฟล์ผู้ใช้ใน SharePoint Online ได้อย่างไร
โปรไฟล์ผู้ใช้ใน SharePoint เป็นตำแหน่งที่ตั้งส่วนกลางที่เก็บข้อมูลเกี่ยวกับผู้ใช้ ให้ความเป็นสมาชิกของไซต์ และติดตามข้อมูลการใช้งาน ช่วยให้ไซต์ของฉัน คุณลักษณะทางสังคม และแบ่งปันโปรไฟล์ระหว่างหลายไซต์ในผู้เช่า เมื่อต้องการรับโปรไฟล์ผู้ใช้ทั้งหมดใน SharePoint Online ให้ทำดังต่อไปนี้:
เข้าสู่ระบบ SharePoint Online Admin >> คลิกที่ "คุณสมบัติเพิ่มเติม" ในการนำทางด้านซ้าย >> คลิกที่ปุ่ม "เปิด" ถัดจาก "โปรไฟล์ผู้ใช้"
ในหน้าโปรไฟล์ผู้ใช้ คลิกที่ "จัดการโปรไฟล์ผู้ใช้" ใต้แท็บบุคคล ใช้การค้นหาเพื่อรับโปรไฟล์ผู้ใช้ของผู้ใช้
หน้านี้ช่วยให้เราได้รับโปรไฟล์ผู้ใช้และคุณสมบัติแต่ละรายการทีละรายการ ตอนนี้เรามาดูวิธีรับโปรไฟล์ผู้ใช้ทั้งหมดใน SharePoint Online โดยใช้ PowerShell
SharePoint Online: PowerShell เพื่อรับโปรไฟล์ผู้ใช้ทั้งหมด
มารับข้อมูลโปรไฟล์ผู้ใช้และรายงานทั้งหมดใน SharePoint Online โดยใช้ PowerShell ตรวจสอบให้แน่ใจว่าคุณได้ติดตั้งโมดูล Azure AD PowerShell ก่อนที่จะรันสคริปต์นี้
#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"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
#Variables
$AdminSiteUrl = "https://crescent-admin.sharepoint.com"
$CSVPath = "C:\Temp\UserProfiles.csv"
#Get Credentials
$Cred = Get-Credential
#Connect to AzureAD
Connect-AzureAD -Credential $Cred
#Get All Users from AzureAD
$AllUsers = Get-AzureADUser -All:$True
Write-host "Total Number of User Profiles Found:"$AllUsers.Count
#Setup the context
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
$Ctx.Credentials = $Credentials
#Collect User data
$PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Ctx)
$UserDataCollection = @()
$Counter = 1
ForEach($User in $AllUsers)
{
#Get User Profile
$UserProfile = $PeopleManager.GetPropertiesFor(('i:0#.f|membership|'+$User.UserPrincipalName))
$Ctx.Load($UserProfile)
$Ctx.ExecuteQuery()
Write-Progress -Activity "Extracting User Profile Data..." -Status "Getting User Profile $Counter of $($AllUsers.Count)" -PercentComplete (($Counter / $AllUsers.Count) * 100)
#Get User Profile Data
$UserData = New-Object PSObject
ForEach($Key in $UserProfile.UserProfileProperties.Keys)
{
$UserData | Add-Member NoteProperty $Key($UserProfile.UserProfileProperties[$Key])
}
$UserDataCollection += $UserData
$Counter++
}
#Export Data to CSV File
$UserDataCollection | Export-Csv -Path $CSVPath -NoTypeInformation
PowerShell นี้รับโปรไฟล์ผู้ใช้และคุณสมบัติทั้งหมดใน SharePoint Online
ส่งออกมูลค่าทรัพย์สินโปรไฟล์ผู้ใช้ของผู้ใช้ทั้งหมดโดยใช้ PnP PowerShell
สคริปต์ PowerShell นี้รับค่าคุณสมบัติ “Office” จากโปรไฟล์ผู้ใช้ทั้งหมดโดยใช้ Get-PnPUserProfileProperty cmdlet และส่งออกเป็นไฟล์ CSV:
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$SPOPropertyName = "Office"
$CSVPath = "C:\Temp\UserProfileProperty.csv"
Try {
#Connect to AzureAD
Connect-AzureAD
#Get All Users of the Domain from AzureAD
$AllUsers = Get-AzureADUser -All:$True -Filter "UserType eq 'Member'"
Write-host "Total Number of User Profiles Found:"$AllUsers.Count
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Iterate through All Users
$Counter = 1
$UserProfileData = @()
ForEach($User in $AllUsers)
{
Write-host "`nGetting User Profile Property for: $($User.UserPrincipalName)" -f Yellow
#Get the User Property value from SharePoint
$UserProfile = Get-PnPUserProfileProperty -Account ($User.UserPrincipalName)
#Collect the data
$UserProfileData += New-Object PSObject -Property @{
'User Account' = $UserProfile.UserProfileProperties["UserName"]
'Location' = $UserProfile.UserProfileProperties[$SPOPropertyName]
}
$Counter++
Write-Progress -Activity "Getting User Profile Data..." -Status "Getting User Profile $Counter of $($AllUsers.Count)" -PercentComplete (($Counter / $AllUsers.Count) * 100)
}
#Export the data to CSV
$UserProfileData | Export-Csv $CSVPath -NoTypeInformation
write-host -f Green "User Profiles Data Exported Successfully to:" $CSVPath
}
Catch {
write-host -f Red "Error Getting User Profile Property!" $_.Exception.Message
}
โดยสรุป การใช้สคริปต์ PowerShell เพื่อดึงรายการโปรไฟล์ผู้ใช้ทั้งหมดใน SharePoint Online เป็นวิธีที่มีประสิทธิภาพและมีประสิทธิภาพในการจัดการและจัดระเบียบข้อมูลผู้ใช้ภายในองค์กร ด้วยการใช้ PowerShell คุณสามารถดึงรายการโปรไฟล์ผู้ใช้ทั้งหมดจากผู้เช่า SharePoint Online ของคุณได้อย่างง่ายดาย คุณสามารถใช้ Microsoft Excel เพื่อวิเคราะห์ จัดเรียง และกรองข้อมูลโปรไฟล์ผู้ใช้เพิ่มเติมได้
นี่คือโพสต์อื่นของฉันเพื่อรับคุณสมบัติโปรไฟล์ผู้ใช้ทั้งหมด: SharePoint Online: PowerShell เพื่อรับคุณสมบัติโปรไฟล์ผู้ใช้


