SharePoint 2010: Export User Profile Properties to a Text File using PowerShell
You can use the following PowerShell code to export a specific list of SharePoint User Profile properties to a text file.
[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()
Other Languages
This article is also available in the following languages: