How to enumerate user profiles and their properties in SharePoint 2010 using PowerShell

When administering a large SharePoint 2010 deployment, there are times when you may need to take an inventory of the user profiles in your profile store – perhaps to find users with a common property or characteristic, run some comparisons of your SharePoint profiles to Active Directory, or do some other administrative task.

Here’s a simple PowerShell script that enumerates all user profiles in the context of your SharePoint site and emits some of their properties, such as Display Name, AccountName, and workEmail.

Note:  The account which will be executing this script needs to have Full Control access to the User Profile Service application.   Follow these two steps:

1) Go to  Central Administration > Manage service applications > select (highlight) your user profile application > click on Administrators button on the ribbon and add your account.

2) Go to  Central Administration > Manage service applications > select (highlight) your user profile application > click on Permissions button on the ribbon and add your account with Full Control – make sure to check the “Full Control” checkbox!


[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# Enter your SharePoint site URL here...
$site = new-object Microsoft.SharePoint.SPSite("http://...");

$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);

$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

$AllProfiles = $ProfileManager.GetEnumerator()

write-host "Display Name ;  AccountName ; Email ; "

foreach($profile in $AllProfiles)
{

$DisplayName = $profile.DisplayName

$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value

$workEmail = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::workEmail].Value

write-host $DisplayName, ";", $AccountName, ";" , $workEmail, ";"

}
write-host "Finished."

$site.Dispose()

A full list of SP 2010 user profile properties is available on MSDN here:

http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.propertyconstants_members.aspx

4 Responses to “How to enumerate user profiles and their properties in SharePoint 2010 using PowerShell”


  1. 1 Rahul June 13, 2011 at 4:34 am

    Good Post, helped me for PropertyConstants

  2. 2 Kevin Parker June 29, 2011 at 2:32 pm

    Thank you! This post helped me with a huge permissions headache I ran into trying to provision hundreds of My Sites through PowerShell.

  3. 3 Jet Dela Cruz March 8, 2012 at 2:16 am

    Thank you too for the script..

  4. 4 KEF May 18, 2012 at 1:18 pm

    Is there a way to exclude certain users and groups from the output?


Leave a comment




RSS Information Week Headlines

  • An error has occurred; the feed is probably down. Try again later.

RSS SharePoint Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS InfoPath Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Joel Oleson Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Bud Ratliff blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Susan Hanley’s KM Blog

  • An error has occurred; the feed is probably down. Try again later.

Blog Stats

  • 401,811 hits