The following script will iterate through all the user profiles and return the account name.
Add-PSSnapin microsoft.sharepoint.powershell;
#Load SharePoint User Profile assemblies
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.UserProfiles”)
#Get Context
$serviceContext = Get-SPServiceContext -Site “[Site Name]”
#Instantiate User Profile Manager
$userProfileConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
#Get All User Profiles
$profiles = $userProfileConfigManager.GetEnumerator();
#Loop through all user profiles and display account name
foreach($profile in $profiles)
{
$profile.get_Item(“AccountName”);
}
This script is a helpful way to retrieve user accounts from SharePoint.
LikeLike