Share via


PowerShell script to list all User Profiles in an SSP

I had few thousand user profiles in my SSP and needed to delete them. So here is a script that I wrote to list all the user profiles in an SSP. If you need to remove the user profiles, then just use the UserProfileManager.RemoveUserProfile method and pass it the UserProfile.Id property.

###################################################################################################

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")

###########################
# "PUT THE SSP NAME HERE"
$SSPName = "SharedServices1"
###########################
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSPName)
$UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
$enumProfiles = $UPManager.GetEnumerator();
"Total User Profiles available:" + $UPManager.Count
$count=0;
foreach ($oUser in $enumProfiles)
{
    $count = $count + 1;
    "(" + $count + ") " + $oUser.Item("PreferredName");
}

###################################################################################################

Disclaimer: The above code is provided "As Is". This is just a sample code and is not production ready.

Comments