Using PowerShell To Get All The Users From SharePoint’s User Profile Service

Using PowerShell To Get All The Users From SharePoint’s User Profile Service

Are you interested in using PowerShell to get users from SharePoint?  Brace yourself.  It’s a lot easier than you think.  Below is a simple way to make that happen.  If you need more information contact us directly.

Powershell Script Help

A simple PowerShell script to get a list of all the accounts in the User Profile Service.

add-pssnapin "Microsoft.Sharepoint.Powershell";

$siteList = Get-SPSite;
$serviceContext = Get-SPServiceContext($siteList[0]);
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);

foreach($usrProfile in $profileManager.GetEnumerator()) {
Write-Host $usrProfile.AccountName "|" $usrProfile.DisplayName;

Purpose and Intention

This script is intended to be run in a SharePoint 2013 development environment using an account that has the permissions to work the User Profile Service.

This script breaks down into the following major parts: Load the SharePoint add-in, establish a connection to the SharePoint server, use the UserProfileManager to get the data, and finally send the results to the screen.


Get-SPSite –

Get-SPServiceContext –

Microsoft.Office.Server.UserProfiles.UserProfileManager –

Next Steps

Review our case studies and engagements where we helped companies just like yours solve a variety of business needs.

About Oakwood

Since 1981, Oakwood has been helping companies of all sizes, across all industries, solve their business problems.  We bring world-class consultants to architect, design and deploy technology solutions to move your company forward.   Our proven approach guarantees better business outcomes.  With flexible engagement options, your project is delivered on-time and on budget.  11,000 satisfied clients can’t be wrong.

Related Posts