PowerShell script to list all User Profiles in an SSP

PowerShell script to list all User Profiles in an SSP

  • Comments 1

Moved from http://blogs.msdn.com/vijgang

I had few thousand user profiles in my SharePoint 2007 SSP and needed to delete them. So here is a script that lists 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.

Leave a Comment
  • Please add 6 and 2 and type the answer here:
  • Post
  • In an effort to make this generic in my small single SSP farms, I changed the $SSPName line to :

    $SSPName = ([xml](stsadm -o enumssp -default)).SelectSingleNode("/Ssps/Ssp/@Name").Value

    There are probably nicer ways to do this, but it serves my purpose.

Page 1 of 1 (1 items)