ค้นหาเว็บไซต์

รับและส่งออกคุณสมบัติโปรไฟล์ผู้ใช้โดยใช้ PowerShell ใน SharePoint Server


คุณจำเป็นต้องส่งออกคุณสมบัติโปรไฟล์ผู้ใช้จาก SharePoint เพื่อการรายงานหรือเพื่อวัตถุประสงค์อื่นหรือไม่ เป็นข้อกำหนดทั่วไปใน SharePoint เพื่อจัดเตรียมรายงานจากคุณสมบัติโปรไฟล์ผู้ใช้ นี่คือสคริปต์ PowerShell ของฉันเพื่อรับคุณสมบัติโปรไฟล์ผู้ใช้ใน SharePoint

สำคัญ: ตรวจสอบให้แน่ใจว่าแอปพลิเคชันบริการโปรไฟล์ผู้ใช้ถูกสร้างขึ้น ติดตั้งและทำงานก่อนที่จะรันสคริปต์เหล่านี้! และทำงานเป็นผู้ดูแลฟาร์ม!!

รับคุณสมบัติโปรไฟล์ผู้ใช้ใน SharePoint 2013/2016 โดยใช้ PowerShell

PowerShell เป็นเครื่องมืออเนกประสงค์ที่สามารถใช้เพื่อทำงานหลายอย่างใน SharePoint โดยอัตโนมัติ ในบล็อกโพสต์นี้ มาดูค่าคุณสมบัติโปรไฟล์ผู้ใช้สำหรับผู้ใช้ที่กำหนดกัน:


#Configuration Variables
$SiteURL = "https://mysite.crescent.com"
$UserLogin="Crescent\Salaudeen"

#Get Objects
$ServiceContext  = Get-SPServiceContext -site $SiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($UserLogin) 

#Retrieve User Profile Properties
Write-host $UserProfile["PreferredName"]
Write-host $UserProfile["WorkEmail"]

คุณไม่ได้จำกัดอยู่เพียงฟิลด์เหล่านี้ แต่ยังมีฟิลด์อีกมากมายในโปรไฟล์ผู้ใช้ หากต้องการรับคุณสมบัติโปรไฟล์ผู้ใช้ที่มีอยู่ทั้งหมด ให้ใช้:


$UserProfile.Properties | Select DisplayName, Name

PowerShell เพื่อสืบค้นและส่งออกคุณสมบัติโปรไฟล์ผู้ใช้ของผู้ใช้ทั้งหมดใน SharePoint:

มาใช้ PowerShell เพื่อรับคุณสมบัติโปรไฟล์ผู้ใช้ทั้งหมดและส่งออกเป็น CSV


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://portal.crescent.com"
$outputReport = "c:\user_profiles.csv"

#Get Objects
$ServiceContext  = Get-SPServiceContext -site $SiteURL
$UPM = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get All User Profiles
$UserProfiles = $UPM.GetEnumerator()
Write-host "Total Number of User Profiles found:"$UserProfiles.Count

#Array to hold Profiles
$ProfileDataCollection = @() 

#Iterate through each profile
foreach ($Profile in $UserProfiles)
{
    $ProfileData = New-Object PSObject 
    #Retrieve User profile Properties  
    $ProfileData | Add-Member -MemberType NoteProperty -name "Account" -value $Profile["AccountName"]
    $ProfileData | Add-Member -MemberType NoteProperty -name "Display Name" -value $Profile["PreferredName"]
    $ProfileData | Add-Member -MemberType NoteProperty -name "E-Mail" -value $Profile["WorkEmail"]
    $ProfileData | Add-Member -MemberType NoteProperty -name "Manager" -value $Profile["Manager"]
    $ProfileData | Add-Member -MemberType NoteProperty -name "Department" -value $Profile["Department"]
   
    #Add to Array
    $ProfileDataCollection+=$ProfileData
    write-host "Processed Profile:"$profile["PreferredName"]
}
#Export User Profile data to CSV
$ProfileDataCollection | Export-Csv $outputReport -NoType

สคริปต์นี้จะส่งออกคุณสมบัติโปรไฟล์ผู้ใช้ที่กำหนดของผู้ใช้ทั้งหมดเป็นไฟล์ CSV:

หากคุณต้องการส่งออกคุณสมบัติโปรไฟล์ผู้ใช้จาก SharePoint Online ให้ใช้: SharePoint Online: ส่งออกคุณสมบัติโปรไฟล์ผู้ใช้เป็น CSV โดยใช้ PowerShell

บทความที่เกี่ยวข้อง