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.

References

Get-SPSite – http://technet.microsoft.com/en-us/library/ff607950(v=office.15).aspx

Get-SPServiceContext – http://technet.microsoft.com/en-us/library/ff607716(v=office.15).aspx

Microsoft.Office.Server.UserProfiles.UserProfileManager – http://msdn.microsoft.com/en-s/library/microsoft.office.server.userprofiles.userprofilemanager.aspx


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.


Like what you've read? Please spread the word!

Leave a Reply

Your email address will not be published. Required fields are marked *