SharePoint 2010: Export user profile properties to a text file or Excel using powershell

Source: Internet
Author: User

Export to txt

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")             [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")             [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")                        # SharePoint site URL             $site = new-object Microsoft.SharePoint.SPSite("http://contoso.com/");             $ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);                $ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)            $AllProfiles = $ProfileManager.GetEnumerator()            $file = New-Object System.IO.StreamWriter "D:\UserProfiles.txt";            $file.Writeline("CustomID|Accountname|PreferredName|UserName|FirstName|LastName|DeskPhoneNo|Department|Title|Manager|WorkEmail|Office|Classification|ServiceDate");            foreach($profile in $AllProfiles)             {                $CustomID = $profile["CustomID"].value                $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value                 $PreferredName = $profile["PreferredName"].value                $UserName = $profile["UserName"].value                $FirstName = $profile["FirstName"].value                $LastName = $profile["LastName"].value                $DeskPhoneNo = $profile["DeskPhoneNo"].value                $Department = $profile["Department"].value                $Title = $profile["Title"].value                $Manager = $profile["Manager"].value                $WorkEmail = $profile["WorkEmail"].value                $Office = $profile["Office"].value                $Classification = $profile["Classification"].value                $ServiceDate = $profile["ServiceDate"].value                $file.Writeline($CustomID+"|"+$AccountName+"|"+$PreferredName+"|"+$UserName+"|"+$FirstName+"|"+$LastName+"|"+$DeskPhoneNo+"|"+$Department+"|"+$Title+"|"+$Manager+"|"+$WorkEmail+"|"+$Office+"|"+$Classification+"|"+$ServiceDate);            }            $file.close();                        $site.Dispose()

Export to excel

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue$siteUrl = "http://sp2010"$outputFile = "C:\UserProfiles.csv"$serviceContext = Get-SPServiceContext -Site $siteUrl$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);$profiles = $profileManager.GetEnumerator()Write-Host "Exporting profiles" $collection = @()foreach ($profile in $profiles) {   $profileData = "" | select "AccountName","FirstName", "LastName","PreferredName","WorkPhone"   $profileData.AccountName = $profile["AccountName"].Value   $profileData.FirstName = $profile["FirstName"].Value   $profileData.LastName = $profile["LastName"].Value   $profileData.PreferredName = $profile["PreferredName"].Value   $profileData.WorkPhone = $profile["WorkPhone"].Value   $collection += $profileData}$collection | Export-Csv $outputFile -NoTypeInformation

Export garbled characters

Export-Csv $outputFile -NoTypeInformation -Encoding Unicode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.