Thursday, August 23, 2012

Powershell exporting user profile information

Scenario:
I was asked by my client to export User Profile data into Excel.

Solution:
Answer was Powershell. I googled and found a good script to start with, I just added few more things and tested it. Here's the script

Code:

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
Article:
User Profile export

4 comments:

Unknown April 11, 2013 at 7:09 PM  

I need to export all user profiles. With all the information, so I can compare any changes. Is there a script that does that?

Unknown April 11, 2013 at 7:10 PM  

Is there a way too export all user profiles with all attributes, so I can compare, if there are any changes

Sandeep April 12, 2013 at 12:50 AM  

It doesn't do any comparison - only export