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.